Package com.caucho.burlap.client
Class MicroBurlapInput
- java.lang.Object
-
- com.caucho.burlap.client.MicroBurlapInput
-
public class MicroBurlapInput extends java.lang.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
Fields Modifier and Type Field Description protected java.util.Date
date
protected java.lang.StringBuffer
entity
protected java.lang.String
method
protected int
peek
protected boolean
peekTag
protected java.util.Vector
refs
protected java.lang.StringBuffer
sbuf
protected java.util.Calendar
utcCalendar
-
Constructor Summary
Constructors Constructor Description MicroBurlapInput()
Creates an uninitialized Burlap input stream.MicroBurlapInput(java.io.InputStream is)
Creates a new Burlap input stream, initialized with an underlying input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
completeCall()
Completes reading the call.void
completeReply()
Completes reading the reply.protected java.io.IOException
expectBeginTag(java.lang.String expect, java.lang.String tag)
protected java.io.IOException
expectedChar(java.lang.String expect, int actualChar)
protected void
expectEndTag(java.lang.String tag)
protected void
expectStartTag(java.lang.String tag)
java.lang.String
getMethod()
Returns a call's method.void
init(java.io.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 java.io.ByteArrayOutputStream
parseBytes(java.io.ByteArrayOutputStream bos)
Parses a byte array.protected long
parseDate(java.util.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 java.lang.String
parseString()
Parses a string value from the stream.protected java.lang.StringBuffer
parseString(java.lang.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 java.lang.Object
readExtensionObject(java.lang.Class expectedClass, java.lang.String tag)
Reads object unknown to MicroBurlapInput.java.util.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.java.lang.Object
readList(java.lang.Class expectedClass, java.lang.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.java.lang.Object
readMap(java.lang.Class expectedClass, java.lang.String type)
Reads an object from the input stream.java.lang.Object
readObject(java.lang.Class expectedClass)
Reads an arbitrary object the input stream.BurlapRemote
readRemote()
Reads a remote value from the input stream.java.lang.Object
readReply(java.lang.Class expectedClass)
Reads a reply as an object.java.lang.String
readString()
Reads a string value from the input stream.java.lang.String
readType()
Reads a type value from the input stream.long
readUTCDate()
Reads a date value from the input stream.java.lang.Object
resolveRemote(java.lang.String type, java.lang.String url)
Resolves a remote object.protected int
skipWhitespace()
void
startCall()
Starts reading the callboolean
startReply()
Starts reading the reply.
-
-
-
Field Detail
-
peek
protected int peek
-
peekTag
protected boolean peekTag
-
date
protected java.util.Date date
-
utcCalendar
protected java.util.Calendar utcCalendar
-
refs
protected java.util.Vector refs
-
method
protected java.lang.String method
-
sbuf
protected java.lang.StringBuffer sbuf
-
entity
protected java.lang.StringBuffer entity
-
-
Method Detail
-
getMethod
public java.lang.String getMethod()
Returns a call's method.
-
init
public void init(java.io.InputStream is)
Initialize the Burlap input stream with a new underlying stream. Applications can useinit(InputStream)
to reuse MicroBurlapInput to save garbage collection.
-
startCall
public void startCall() throws java.io.IOException
Starts reading the callA successful completion will have a single value:
<burlap:call> <method>method</method>
- Throws:
java.io.IOException
-
completeCall
public void completeCall() throws java.io.IOException
Completes reading the call.</burlap:call>
- Throws:
java.io.IOException
-
readReply
public java.lang.Object readReply(java.lang.Class expectedClass) throws java.lang.Exception
Reads a reply as an object. If the reply has a fault, throws the exception.- Throws:
java.lang.Exception
-
startReply
public boolean startReply() throws java.io.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:
java.io.IOException
-
completeReply
public void completeReply() throws java.io.IOException
Completes reading the reply.</burlap:reply>
- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException
Reads a boolean value from the input stream.- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException
Reads an integer value from the input stream.- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
Reads a long value from the input stream.- Throws:
java.io.IOException
-
readUTCDate
public long readUTCDate() throws java.io.IOException
Reads a date value from the input stream.- Throws:
java.io.IOException
-
readLocalDate
public long readLocalDate() throws java.io.IOException
Reads a date value from the input stream.- Throws:
java.io.IOException
-
readRemote
public BurlapRemote readRemote() throws java.io.IOException
Reads a remote value from the input stream.- Throws:
java.io.IOException
-
readString
public java.lang.String readString() throws java.io.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:
java.io.IOException
-
readBytes
public byte[] readBytes() throws java.io.IOException
Reads a byte array from the input stream.The two valid possibilities are either a <null> or a <base64>.
- Throws:
java.io.IOException
-
readObject
public java.lang.Object readObject(java.lang.Class expectedClass) throws java.io.IOException
Reads an arbitrary object the input stream.- Throws:
java.io.IOException
-
readType
public java.lang.String readType() throws java.io.IOException
Reads a type value from the input stream.<type>a utf-8 encoded string</type>
- Throws:
java.io.IOException
-
readLength
public int readLength() throws java.io.IOException
Reads a length value from the input stream. If the length isn't specified, returns -1.<length>integer</length>
- Throws:
java.io.IOException
-
resolveRemote
public java.lang.Object resolveRemote(java.lang.String type, java.lang.String url) throws java.io.IOException
Resolves a remote object.- Throws:
java.io.IOException
-
readFault
public java.util.Hashtable readFault() throws java.io.IOException
Reads a fault.- Throws:
java.io.IOException
-
readMap
public java.lang.Object readMap(java.lang.Class expectedClass, java.lang.String type) throws java.io.IOException
Reads an object from the input stream.- Parameters:
expectedClass
- the calling routine's expected classtype
- the type from the stream- Throws:
java.io.IOException
-
readExtensionObject
protected java.lang.Object readExtensionObject(java.lang.Class expectedClass, java.lang.String tag) throws java.io.IOException
Reads object unknown to MicroBurlapInput.- Throws:
java.io.IOException
-
readList
public java.lang.Object readList(java.lang.Class expectedClass, java.lang.String type, int length) throws java.io.IOException
Reads a list object from the input stream.- Parameters:
expectedClass
- the calling routine's expected classtype
- the type from the streamlength
- the expected length, -1 for unspecified length- Throws:
java.io.IOException
-
parseInt
protected int parseInt() throws java.io.IOException
Parses an integer value from the stream.- Throws:
java.io.IOException
-
parseLong
protected long parseLong() throws java.io.IOException
Parses a long value from the stream.- Throws:
java.io.IOException
-
parseDate
protected long parseDate(java.util.Calendar calendar) throws java.io.IOException
Parses a date value from the stream.- Throws:
java.io.IOException
-
parseString
protected java.lang.String parseString() throws java.io.IOException
Parses a string value from the stream. string buffer is used for the result.- Throws:
java.io.IOException
-
parseString
protected java.lang.StringBuffer parseString(java.lang.StringBuffer sbuf) throws java.io.IOException
Parses a string value from the stream. The burlap object's string buffer is used for the result.- Throws:
java.io.IOException
-
parseBytes
protected byte[] parseBytes() throws java.io.IOException
Parses a byte array.- Throws:
java.io.IOException
-
parseBytes
protected java.io.ByteArrayOutputStream parseBytes(java.io.ByteArrayOutputStream bos) throws java.io.IOException
Parses a byte array.- Throws:
java.io.IOException
-
expectStartTag
protected void expectStartTag(java.lang.String tag) throws java.io.IOException
- Throws:
java.io.IOException
-
expectEndTag
protected void expectEndTag(java.lang.String tag) throws java.io.IOException
- Throws:
java.io.IOException
-
parseTag
protected boolean parseTag() throws java.io.IOException
Parses a tag. Returns true if it's a start tag.- Throws:
java.io.IOException
-
expectedChar
protected java.io.IOException expectedChar(java.lang.String expect, int actualChar)
-
expectBeginTag
protected java.io.IOException expectBeginTag(java.lang.String expect, java.lang.String tag)
-
skipWhitespace
protected int skipWhitespace() throws java.io.IOException
- Throws:
java.io.IOException
-
isWhitespace
protected boolean isWhitespace(int ch) throws java.io.IOException
- Throws:
java.io.IOException
-
read
protected int read() throws java.io.IOException
- Throws:
java.io.IOException
-
-