com.caucho.burlap.client
Class MicroBurlapOutput

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

public class MicroBurlapOutput
extends java.lang.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
MicroBurlapOutput()
          Creates an uninitialized Burlap output stream.
MicroBurlapOutput(java.io.OutputStream os)
          Creates a new Burlap output stream, initialized with an underlying output stream.
 
Method Summary
static char base64encode(int d)
          Converts the digit to its base64 encoding.
 void call(java.lang.String method, java.lang.Object[] args)
          Writes a complete method call.
 void completeCall()
          Writes the method call:
 void init(java.io.OutputStream os)
           
 void print(java.lang.String s)
          Prints a string as ascii to the stream.
 void printBytes(byte[] data, int offset, int length)
          Prints a byte array to the stream, properly encoded in base64.
 void printDate(java.util.Calendar calendar)
          Prints a date.
 void printInt(int v)
          Prints an integer to the stream.
 void printLong(long v)
          Prints a long to the stream.
 void printString(java.lang.String v)
          Prints a string to the stream, properly encoded.
 void startCall(java.lang.String method)
          Writes the method call:
 void writeBoolean(boolean value)
          Writes a boolean value to the stream.
 void writeBytes(byte[] buffer, int offset, int length)
          Writes a byte array to the stream using base64 encoding.
 void writeCustomObject(java.lang.Object object)
          Applications which override this can do custom serialization.
 void writeInt(int value)
          Writes an integer value to the stream.
 void writeListBegin(int length, java.lang.String type)
          Writes the list header to the stream.
 void writeListEnd()
          Writes the tail of the list to the stream.
 void writeLocalDate(long time)
          Writes a date to the stream using ISO8609.
 void writeLong(long value)
          Writes a long value to the stream.
 void writeMapBegin(java.lang.String type)
          Writes the map header to the stream.
 void writeMapEnd()
          Writes the tail of the map to the stream.
 void writeNull()
          Writes a null value to the stream.
 void writeObject(java.lang.Object object)
          Writes a generic object.
 void writeRef(int value)
          Writes a reference.
 void writeRemote(java.lang.String type, java.lang.String url)
          Writes a remote object reference to the stream.
 void writeString(java.lang.String value)
          Writes a string value to the stream using UTF-8 encoding.
 void writeUTCDate(long time)
          Writes a date to the stream using ISO8609.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MicroBurlapOutput

public MicroBurlapOutput(java.io.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(java.io.OutputStream os)

call

public void call(java.lang.String method,
                 java.lang.Object[] args)
          throws java.io.IOException
Writes a complete method call.

Throws:
java.io.IOException

startCall

public void startCall(java.lang.String method)
               throws java.io.IOException
Writes the method call:
 <burlap:request>
   <method>add</method>
 

Parameters:
method - the method name to call.
Throws:
java.io.IOException

completeCall

public void completeCall()
                  throws java.io.IOException
Writes the method call:
 </burlap:request>
 

Throws:
java.io.IOException

writeBoolean

public void writeBoolean(boolean value)
                  throws java.io.IOException
Writes 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:
java.io.IOException

writeInt

public void writeInt(int value)
              throws java.io.IOException
Writes 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:
java.io.IOException

writeLong

public void writeLong(long value)
               throws java.io.IOException
Writes 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:
java.io.IOException

writeNull

public void writeNull()
               throws java.io.IOException
Writes 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:
java.io.IOException

writeString

public void writeString(java.lang.String value)
                 throws java.io.IOException
Writes a string value to the stream using UTF-8 encoding. The string will be written with the following syntax:
 <string>12.3e10</string>
 
If the value is null, it will be written as
 <null></null>
 

Parameters:
value - the string value to write.
Throws:
java.io.IOException

writeBytes

public void writeBytes(byte[] buffer,
                       int offset,
                       int length)
                throws java.io.IOException
Writes a byte array to the stream using base64 encoding. The array will be written with the following syntax:
 <base64>dJmO==</base64>
 
If the value is null, it will be written as
 <null></null>
 

Parameters:
value - the string value to write.
Throws:
java.io.IOException

writeUTCDate

public void writeUTCDate(long time)
                  throws java.io.IOException
Writes a date to the stream using ISO8609.
 <date>19980508T095131Z</date>
 

Parameters:
value - the date in milliseconds from the epoch in UTC
Throws:
java.io.IOException

writeLocalDate

public void writeLocalDate(long time)
                    throws java.io.IOException
Writes a date to the stream using ISO8609.
 <date>19980508T095131Z</date>
 

Parameters:
value - the date in milliseconds from the epoch in local timezone
Throws:
java.io.IOException

writeRef

public void writeRef(int value)
              throws java.io.IOException
Writes a reference.
 <ref>123</ref>
 

Parameters:
value - the integer value to write.
Throws:
java.io.IOException

writeObject

public void writeObject(java.lang.Object object)
                 throws java.io.IOException
Writes a generic object. writeObject understands the following types: Unknown objects will call writeCustomObject.

Throws:
java.io.IOException

writeCustomObject

public void writeCustomObject(java.lang.Object object)
                       throws java.io.IOException
Applications which override this can do custom serialization.

Parameters:
object - the object to write.
Throws:
java.io.IOException

writeListBegin

public void writeListBegin(int length,
                           java.lang.String type)
                    throws java.io.IOException
Writes the list header to the stream. List writers will call writeListBegin followed by the list contents and then call writeListEnd.
 <list>
   <type>java.util.ArrayList</type>
   <length>3</length>
   <int>1</int>
   <int>2</int>
   <int>3</int>
 </list>
 

Throws:
java.io.IOException

writeListEnd

public void writeListEnd()
                  throws java.io.IOException
Writes the tail of the list to the stream.

Throws:
java.io.IOException

writeMapBegin

public void writeMapBegin(java.lang.String type)
                   throws java.io.IOException
Writes the map header to the stream. Map writers will call writeMapBegin followed by the map contents and then call writeMapEnd.
 <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:
java.io.IOException

writeMapEnd

public void writeMapEnd()
                 throws java.io.IOException
Writes the tail of the map to the stream.

Throws:
java.io.IOException

writeRemote

public void writeRemote(java.lang.String type,
                        java.lang.String url)
                 throws java.io.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:
java.io.IOException

printInt

public void printInt(int v)
              throws java.io.IOException
Prints an integer to the stream.

Parameters:
v - the integer to print.
Throws:
java.io.IOException

printLong

public void printLong(long v)
               throws java.io.IOException
Prints a long to the stream.

Parameters:
v - the long to print.
Throws:
java.io.IOException

printString

public void printString(java.lang.String v)
                 throws java.io.IOException
Prints a string to the stream, properly encoded.

Parameters:
v - the string to print.
Throws:
java.io.IOException

printBytes

public void printBytes(byte[] data,
                       int offset,
                       int length)
                throws java.io.IOException
Prints a byte array to the stream, properly encoded in base64.

Parameters:
data - the bytes to print.
Throws:
java.io.IOException

base64encode

public static char base64encode(int d)
Converts the digit to its base64 encoding.


printDate

public void printDate(java.util.Calendar calendar)
               throws java.io.IOException
Prints a date.

Parameters:
date - the date to print.
Throws:
java.io.IOException

print

public void print(java.lang.String s)
           throws java.io.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:
java.io.IOException