Package com.caucho.burlap.client
Class MicroBurlapInput
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description protected Datedateprotected StringBufferentityprotected Stringmethodprotected intpeekprotected booleanpeekTagprotected Vectorrefsprotected StringBuffersbufprotected CalendarutcCalendar
-
Constructor Summary
Constructors Constructor Description MicroBurlapInput()Creates an uninitialized Burlap input stream.MicroBurlapInput(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 voidcompleteCall()Completes reading the call.voidcompleteReply()Completes reading the reply.protected IOExceptionexpectBeginTag(String expect, String tag)protected IOExceptionexpectedChar(String expect, int actualChar)protected voidexpectEndTag(String tag)protected voidexpectStartTag(String tag)StringgetMethod()Returns a call's method.voidinit(InputStream is)Initialize the Burlap input stream with a new underlying stream.protected booleanisWhitespace(int ch)protected byte[]parseBytes()Parses a byte array.protected ByteArrayOutputStreamparseBytes(ByteArrayOutputStream bos)Parses a byte array.protected longparseDate(Calendar calendar)Parses a date value from the stream.protected intparseInt()Parses an integer value from the stream.protected longparseLong()Parses a long value from the stream.protected StringparseString()Parses a string value from the stream.protected StringBufferparseString(StringBuffer sbuf)Parses a string value from the stream.protected booleanparseTag()Parses a tag.protected intread()booleanreadBoolean()Reads a boolean value from the input stream.byte[]readBytes()Reads a byte array from the input stream.protected ObjectreadExtensionObject(Class expectedClass, String tag)Reads object unknown to MicroBurlapInput.HashtablereadFault()Reads a fault.intreadInt()Reads an integer value from the input stream.intreadLength()Reads a length value from the input stream.ObjectreadList(Class expectedClass, String type, int length)Reads a list object from the input stream.longreadLocalDate()Reads a date value from the input stream.longreadLong()Reads a long value from the input stream.ObjectreadMap(Class expectedClass, String type)Reads an object from the input stream.ObjectreadObject(Class expectedClass)Reads an arbitrary object the input stream.BurlapRemotereadRemote()Reads a remote value from the input stream.ObjectreadReply(Class expectedClass)Reads a reply as an object.StringreadString()Reads a string value from the input stream.StringreadType()Reads a type value from the input stream.longreadUTCDate()Reads a date value from the input stream.ObjectresolveRemote(String type, String url)Resolves a remote object.protected intskipWhitespace()voidstartCall()Starts reading the callbooleanstartReply()Starts reading the reply.
-
-
-
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 useinit(InputStream)to reuse MicroBurlapInput to save garbage collection.
-
startCall
public void startCall() throws IOExceptionStarts reading the callA successful completion will have a single value:
<burlap:call> <method>method</method>
- Throws:
IOException
-
completeCall
public void completeCall() throws IOExceptionCompletes 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 IOExceptionStarts 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 IOExceptionCompletes reading the reply.</burlap:reply>
- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOExceptionReads a boolean value from the input stream.- Throws:
IOException
-
readInt
public int readInt() throws IOExceptionReads an integer value from the input stream.- Throws:
IOException
-
readLong
public long readLong() throws IOExceptionReads a long value from the input stream.- Throws:
IOException
-
readUTCDate
public long readUTCDate() throws IOExceptionReads a date value from the input stream.- Throws:
IOException
-
readLocalDate
public long readLocalDate() throws IOExceptionReads 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 IOExceptionReads 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 IOExceptionReads 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 classtype- 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 classtype- the type from the streamlength- the expected length, -1 for unspecified length- Throws:
IOException
-
parseInt
protected int parseInt() throws IOExceptionParses an integer value from the stream.- Throws:
IOException
-
parseLong
protected long parseLong() throws IOExceptionParses 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 IOExceptionParses 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 IOExceptionParses 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
-
-