com.caucho.burlap.client
Class MicroBurlapInput

java.lang.Object
  extended by com.caucho.burlap.client.MicroBurlapInput

public class MicroBurlapInput
extends Object

Input stream for Burlap requests, compatible with microedition Java. It only uses classes and types available to J2ME. In particular, it does not have any support for the <double> type.

MicroBurlapInput does not depend on any classes other than in J2ME, so it can be extracted independently into a smaller package.

MicroBurlapInput is unbuffered, so any client needs to provide its own buffering.

 InputStream is = ...; // from http connection
 MicroBurlapInput in = new MicroBurlapInput(is);
 String value;

 in.startReply();         // read reply header
 value = in.readString(); // read string value
 in.completeReply();      // read reply footer
 


Field Summary
protected  Date date
           
protected  StringBuffer entity
           
protected  String method
           
protected  int peek
           
protected  boolean peekTag
           
protected  Vector refs
           
protected  StringBuffer sbuf
           
protected  Calendar utcCalendar
           
 
Constructor Summary
MicroBurlapInput()
          Creates an uninitialized Burlap input stream.
MicroBurlapInput(InputStream is)
          Creates a new Burlap input stream, initialized with an underlying input stream.
 
Method Summary
 void completeCall()
          Completes reading the call.
 void completeReply()
          Completes reading the reply.
protected  IOException expectBeginTag(String expect, String tag)
           
protected  IOException expectedChar(String expect, int actualChar)
           
protected  void expectEndTag(String tag)
           
protected  void expectStartTag(String tag)
           
 String getMethod()
          Returns a call's method.
 void init(InputStream is)
          Initialize the Burlap input stream with a new underlying stream.
protected  boolean isWhitespace(int ch)
           
protected  byte[] parseBytes()
          Parses a byte array.
protected  ByteArrayOutputStream parseBytes(ByteArrayOutputStream bos)
          Parses a byte array.
protected  long parseDate(Calendar calendar)
          Parses a date value from the stream.
protected  int parseInt()
          Parses an integer value from the stream.
protected  long parseLong()
          Parses a long value from the stream.
protected  String parseString()
          Parses a string value from the stream.
protected  StringBuffer parseString(StringBuffer sbuf)
          Parses a string value from the stream.
protected  boolean parseTag()
          Parses a tag.
protected  int read()
           
 boolean readBoolean()
          Reads a boolean value from the input stream.
 byte[] readBytes()
          Reads a byte array from the input stream.
protected  Object readExtensionObject(Class expectedClass, String tag)
          Reads object unknown to MicroBurlapInput.
 Hashtable readFault()
          Reads a fault.
 int readInt()
          Reads an integer value from the input stream.
 int readLength()
          Reads a length value from the input stream.
 Object readList(Class expectedClass, String type, int length)
          Reads a list object from the input stream.
 long readLocalDate()
          Reads a date value from the input stream.
 long readLong()
          Reads a long value from the input stream.
 Object readMap(Class expectedClass, String type)
          Reads an object from the input stream.
 Object readObject(Class expectedClass)
          Reads an arbitrary object the input stream.
 BurlapRemote readRemote()
          Reads a remote value from the input stream.
 Object readReply(Class expectedClass)
          Reads a reply as an object.
 String readString()
          Reads a string value from the input stream.
 String readType()
          Reads a type value from the input stream.
 long readUTCDate()
          Reads a date value from the input stream.
 Object resolveRemote(String type, String url)
          Resolves a remote object.
protected  int skipWhitespace()
           
 void startCall()
          Starts reading the call A successful completion will have a single value: <burlap:call> <method>method</method>
 boolean startReply()
          Starts reading the reply.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

peek

protected int peek

peekTag

protected boolean peekTag

date

protected Date date

utcCalendar

protected Calendar utcCalendar

refs

protected Vector refs

method

protected String method

sbuf

protected StringBuffer sbuf

entity

protected StringBuffer entity
Constructor Detail

MicroBurlapInput

public MicroBurlapInput(InputStream is)
Creates a new Burlap input stream, initialized with an underlying input stream.

Parameters:
is - the underlying input stream.

MicroBurlapInput

public MicroBurlapInput()
Creates an uninitialized Burlap input stream.

Method Detail

getMethod

public String getMethod()
Returns a call's method.


init

public void init(InputStream is)
Initialize the Burlap input stream with a new underlying stream. Applications can use init(InputStream) to reuse MicroBurlapInput to save garbage collection.


startCall

public void startCall()
               throws IOException
Starts reading the call

A successful completion will have a single value:

 <burlap:call>
 <method>method</method>
 

Throws:
IOException

completeCall

public void completeCall()
                  throws IOException
Completes reading the call.
 </burlap:call>
 

Throws:
IOException

readReply

public Object readReply(Class expectedClass)
                 throws Exception
Reads a reply as an object. If the reply has a fault, throws the exception.

Throws:
Exception

startReply

public boolean startReply()
                   throws IOException
Starts reading the reply.

A successful completion will have a single value. An unsuccessful one will have a fault:

 <burlap:reply>
 

Returns:
true if success, false for fault.
Throws:
IOException

completeReply

public void completeReply()
                   throws IOException
Completes reading the reply.
 </burlap:reply>
 

Throws:
IOException

readBoolean

public boolean readBoolean()
                    throws IOException
Reads a boolean value from the input stream.

Throws:
IOException

readInt

public int readInt()
            throws IOException
Reads an integer value from the input stream.

Throws:
IOException

readLong

public long readLong()
              throws IOException
Reads a long value from the input stream.

Throws:
IOException

readUTCDate

public long readUTCDate()
                 throws IOException
Reads a date value from the input stream.

Throws:
IOException

readLocalDate

public long readLocalDate()
                   throws IOException
Reads a date value from the input stream.

Throws:
IOException

readRemote

public BurlapRemote readRemote()
                        throws IOException
Reads a remote value from the input stream.

Throws:
IOException

readString

public String readString()
                  throws IOException
Reads a string value from the input stream.

The two valid possibilities are either a <null> or a <string>. The string value is encoded in utf-8, and understands the basic XML escapes: "&123;", "<", ">", "'", """.

 <null></null>
 <string>a utf-8 encoded string</string>
 

Throws:
IOException

readBytes

public byte[] readBytes()
                 throws IOException
Reads a byte array from the input stream.

The two valid possibilities are either a <null> or a <base64>.

Throws:
IOException

readObject

public Object readObject(Class expectedClass)
                  throws IOException
Reads an arbitrary object the input stream.

Throws:
IOException

readType

public String readType()
                throws IOException
Reads a type value from the input stream.
 <type>a utf-8 encoded string</type>
 

Throws:
IOException

readLength

public int readLength()
               throws IOException
Reads a length value from the input stream. If the length isn't specified, returns -1.
 <length>integer</length>
 

Throws:
IOException

resolveRemote

public Object resolveRemote(String type,
                            String url)
                     throws IOException
Resolves a remote object.

Throws:
IOException

readFault

public Hashtable readFault()
                    throws IOException
Reads a fault.

Throws:
IOException

readMap

public Object readMap(Class expectedClass,
                      String type)
               throws IOException
Reads an object from the input stream.

Parameters:
expectedClass - the calling routine's expected class
type - the type from the stream
Throws:
IOException

readExtensionObject

protected Object readExtensionObject(Class expectedClass,
                                     String tag)
                              throws IOException
Reads object unknown to MicroBurlapInput.

Throws:
IOException

readList

public Object readList(Class expectedClass,
                       String type,
                       int length)
                throws IOException
Reads a list object from the input stream.

Parameters:
expectedClass - the calling routine's expected class
type - the type from the stream
length - the expected length, -1 for unspecified length
Throws:
IOException

parseInt

protected int parseInt()
                throws IOException
Parses an integer value from the stream.

Throws:
IOException

parseLong

protected long parseLong()
                  throws IOException
Parses a long value from the stream.

Throws:
IOException

parseDate

protected long parseDate(Calendar calendar)
                  throws IOException
Parses a date value from the stream.

Throws:
IOException

parseString

protected String parseString()
                      throws IOException
Parses a string value from the stream. string buffer is used for the result.

Throws:
IOException

parseString

protected StringBuffer parseString(StringBuffer sbuf)
                            throws IOException
Parses a string value from the stream. The burlap object's string buffer is used for the result.

Throws:
IOException

parseBytes

protected byte[] parseBytes()
                     throws IOException
Parses a byte array.

Throws:
IOException

parseBytes

protected ByteArrayOutputStream parseBytes(ByteArrayOutputStream bos)
                                    throws IOException
Parses a byte array.

Throws:
IOException

expectStartTag

protected void expectStartTag(String tag)
                       throws IOException
Throws:
IOException

expectEndTag

protected void expectEndTag(String tag)
                     throws IOException
Throws:
IOException

parseTag

protected boolean parseTag()
                    throws IOException
Parses a tag. Returns true if it's a start tag.

Throws:
IOException

expectedChar

protected IOException expectedChar(String expect,
                                   int actualChar)

expectBeginTag

protected IOException expectBeginTag(String expect,
                                     String tag)

skipWhitespace

protected int skipWhitespace()
                      throws IOException
Throws:
IOException

isWhitespace

protected boolean isWhitespace(int ch)
                        throws IOException
Throws:
IOException

read

protected int read()
            throws IOException
Throws:
IOException


Copyright © 2013. All Rights Reserved.