Package com.caucho.burlap.client
Class MicroBurlapOutput
- java.lang.Object
-
- com.caucho.burlap.client.MicroBurlapOutput
-
public class MicroBurlapOutput extends Object
Output 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.MicroBurlapOutput does not depend on any classes other than in J2ME, so it can be extracted independently into a smaller package.
MicroBurlapOutput is unbuffered, so any client needs to provide its own buffering.
OutputStream os = ...; // from http connection MicroBurlapOutput out = new MicroBurlapOutput(os); String value; out.startCall("hello"); // start hello call out.writeString("arg1"); // write a string argument out.completeCall(); // complete the call
-
-
Constructor Summary
Constructors Constructor Description MicroBurlapOutput()Creates an uninitialized Burlap output stream.MicroBurlapOutput(OutputStream os)Creates a new Burlap output stream, initialized with an underlying output stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static charbase64encode(int d)Converts the digit to its base64 encoding.voidcall(String method, Object[] args)Writes a complete method call.voidcompleteCall()Writes the method call:voidinit(OutputStream os)voidprint(String s)Prints a string as ascii to the stream.voidprintBytes(byte[] data, int offset, int length)Prints a byte array to the stream, properly encoded in base64.voidprintDate(Calendar calendar)Prints a date.voidprintInt(int v)Prints an integer to the stream.voidprintLong(long v)Prints a long to the stream.voidprintString(String v)Prints a string to the stream, properly encoded.voidstartCall(String method)Writes the method call:voidwriteBoolean(boolean value)Writes a boolean value to the stream.voidwriteBytes(byte[] buffer, int offset, int length)Writes a byte array to the stream using base64 encoding.voidwriteCustomObject(Object object)Applications which override this can do custom serialization.voidwriteInt(int value)Writes an integer value to the stream.voidwriteListBegin(int length, String type)Writes the list header to the stream.voidwriteListEnd()Writes the tail of the list to the stream.voidwriteLocalDate(long time)Writes a date to the stream using ISO8609.voidwriteLong(long value)Writes a long value to the stream.voidwriteMapBegin(String type)Writes the map header to the stream.voidwriteMapEnd()Writes the tail of the map to the stream.voidwriteNull()Writes a null value to the stream.voidwriteObject(Object object)Writes a generic object.voidwriteRef(int value)Writes a reference.voidwriteRemote(String type, String url)Writes a remote object reference to the stream.voidwriteString(String value)Writes a string value to the stream using UTF-8 encoding.voidwriteUTCDate(long time)Writes a date to the stream using ISO8609.
-
-
-
Constructor Detail
-
MicroBurlapOutput
public MicroBurlapOutput(OutputStream os)
Creates a new Burlap output stream, initialized with an underlying output stream.- Parameters:
os- the underlying output stream.
-
MicroBurlapOutput
public MicroBurlapOutput()
Creates an uninitialized Burlap output stream.
-
-
Method Detail
-
init
public void init(OutputStream os)
-
call
public void call(String method, Object[] args) throws IOException
Writes a complete method call.- Throws:
IOException
-
startCall
public void startCall(String method) throws IOException
Writes the method call:<burlap:request> <method>add</method>
- Parameters:
method- the method name to call.- Throws:
IOException
-
completeCall
public void completeCall() throws IOExceptionWrites the method call:</burlap:request>
- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean value) throws IOExceptionWrites a boolean value to the stream. The boolean will be written with the following syntax:<boolean>1</boolean>
- Parameters:
value- the boolean value to write.- Throws:
IOException
-
writeInt
public void writeInt(int value) throws IOExceptionWrites an integer value to the stream. The integer will be written with the following syntax:<int>123</int>
- Parameters:
value- the integer value to write.- Throws:
IOException
-
writeLong
public void writeLong(long value) throws IOExceptionWrites a long value to the stream. The long will be written with the following syntax:<long>123</long>
- Parameters:
value- the long value to write.- Throws:
IOException
-
writeNull
public void writeNull() throws IOExceptionWrites a null value to the stream. The null will be written with the following syntax<null></null>
- Parameters:
value- the string value to write.- Throws:
IOException
-
writeString
public void writeString(String value) throws IOException
Writes a string value to the stream using UTF-8 encoding. The string will be written with the following syntax:If the value is null, it will be written as<string>12.3e10</string>
<null></null>
- Parameters:
value- the string value to write.- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] buffer, int offset, int length) throws IOExceptionWrites a byte array to the stream using base64 encoding. The array will be written with the following syntax:If the value is null, it will be written as<base64>dJmO==</base64>
<null></null>
- Parameters:
value- the string value to write.- Throws:
IOException
-
writeUTCDate
public void writeUTCDate(long time) throws IOExceptionWrites a date to the stream using ISO8609.<date>19980508T095131Z</date>
- Parameters:
value- the date in milliseconds from the epoch in UTC- Throws:
IOException
-
writeLocalDate
public void writeLocalDate(long time) throws IOExceptionWrites a date to the stream using ISO8609.<date>19980508T095131Z</date>
- Parameters:
value- the date in milliseconds from the epoch in local timezone- Throws:
IOException
-
writeRef
public void writeRef(int value) throws IOExceptionWrites a reference.<ref>123</ref>
- Parameters:
value- the integer value to write.- Throws:
IOException
-
writeObject
public void writeObject(Object object) throws IOException
Writes a generic object. writeObject understands the following types:- null
- java.lang.String
- java.lang.Boolean
- java.lang.Integer
- java.lang.Long
- java.util.Date
- byte[]
- java.util.Vector
- java.util.Hashtable
writeCustomObject.- Throws:
IOException
-
writeCustomObject
public void writeCustomObject(Object object) throws IOException
Applications which override this can do custom serialization.- Parameters:
object- the object to write.- Throws:
IOException
-
writeListBegin
public void writeListBegin(int length, String type) throws IOExceptionWrites the list header to the stream. List writers will callwriteListBeginfollowed by the list contents and then callwriteListEnd.<list> <type>java.util.ArrayList</type> <length>3</length> <int>1</int> <int>2</int> <int>3</int> </list>
- Throws:
IOException
-
writeListEnd
public void writeListEnd() throws IOExceptionWrites the tail of the list to the stream.- Throws:
IOException
-
writeMapBegin
public void writeMapBegin(String type) throws IOException
Writes the map header to the stream. Map writers will callwriteMapBeginfollowed by the map contents and then callwriteMapEnd.<map> <type>java.util.Hashtable</type> <string>a</string;<int>1</int> <string>b</string;<int>2</int> <string>c</string;<int>3</int> </map>
- Throws:
IOException
-
writeMapEnd
public void writeMapEnd() throws IOExceptionWrites the tail of the map to the stream.- Throws:
IOException
-
writeRemote
public void writeRemote(String type, String url) throws IOException
Writes a remote object reference to the stream. The type is the type of the remote interface.<remote> <type>test.account.Account</type> <string>http://caucho.com/foo;ejbid=bar</string> </remote>
- Throws:
IOException
-
printInt
public void printInt(int v) throws IOExceptionPrints an integer to the stream.- Parameters:
v- the integer to print.- Throws:
IOException
-
printLong
public void printLong(long v) throws IOExceptionPrints a long to the stream.- Parameters:
v- the long to print.- Throws:
IOException
-
printString
public void printString(String v) throws IOException
Prints a string to the stream, properly encoded.- Parameters:
v- the string to print.- Throws:
IOException
-
printBytes
public void printBytes(byte[] data, int offset, int length) throws IOExceptionPrints a byte array to the stream, properly encoded in base64.- Parameters:
data- the bytes to print.- Throws:
IOException
-
base64encode
public static char base64encode(int d)
Converts the digit to its base64 encoding.
-
printDate
public void printDate(Calendar calendar) throws IOException
Prints a date.- Parameters:
date- the date to print.- Throws:
IOException
-
print
public void print(String s) throws IOException
Prints a string as ascii to the stream. Used for tags, etc. that are known to the ascii.- Parameters:
s- the ascii string to print.- Throws:
IOException
-
-