com.caucho.hessian.micro

Class MicroHessianOutput


public class MicroHessianOutput
extends java.lang.Object

Output stream for Hessian 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.

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

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

 OutputStream os = ...; // from http connection
 MicroHessianOutput out = new MicroHessianOutput(os);
 String value;

 out.startCall("hello");  // start hello call
 out.writeString("arg1"); // write a string argument
 out.completeCall();      // complete the call
 

Field Summary

protected OutputStream
os

Constructor Summary

MicroHessianOutput()
Creates an uninitialized Hessian output stream.
MicroHessianOutput(OutputStream os)
Creates a new Hessian output stream, initialized with an underlying output stream.

Method Summary

void
completeCall()
Writes the method call:
 z
 
void
init(OutputStream os)
void
printLenString(String v)
Prints a string to the stream, encoded as UTF-8 with preceeding length
void
printString(String v)
Prints a string to the stream, encoded as UTF-8
void
printString(String v, int offset, int length)
Prints a string to the stream, encoded as UTF-8
void
startCall(String method)
Writes the method call:
 c major minor
 m b16 b8 method-namek
 
void
writeBoolean(boolean value)
Writes a boolean value to the stream.
void
writeBytes(byte[] buffer)
Writes a byte array to the stream.
void
writeBytes(byte[] buffer, int offset, int length)
Writes a byte array to the stream.
void
writeCustomObject(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, String type)
Writes the list header to the stream.
void
writeListEnd()
Writes the tail of the list to the stream.
void
writeLong(long value)
Writes a long value to the stream.
void
writeMapBegin(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(Object object)
Writes a generic object to the output stream.
void
writeRef(int value)
Writes a reference.
void
writeRemote(String type, String url)
Writes a remote object reference to the stream.
void
writeString(String value)
Writes a string value to the stream using UTF-8 encoding.
void
writeUTCDate(long time)
Writes a date to the stream.

Field Details

os

protected OutputStream os

Constructor Details

MicroHessianOutput

public MicroHessianOutput()
Creates an uninitialized Hessian output stream.

MicroHessianOutput

public MicroHessianOutput(OutputStream os)
Creates a new Hessian output stream, initialized with an underlying output stream.
Parameters:
os - the underlying output stream.

Method Details

completeCall

public void completeCall()
            throws IOException
Writes the method call:
 z
 

init

public void init(OutputStream os)

printLenString

public void printLenString(String v)
            throws IOException
Prints a string to the stream, encoded as UTF-8 with preceeding length
Parameters:
v - the string to print.

printString

public void printString(String v)
            throws IOException
Prints a string to the stream, encoded as UTF-8
Parameters:
v - the string to print.

printString

public void printString(String v,
                        int offset,
                        int length)
            throws IOException
Prints a string to the stream, encoded as UTF-8
Parameters:
v - the string to print.

startCall

public void startCall(String method)
            throws IOException
Writes the method call:
 c major minor
 m b16 b8 method-namek
 
Parameters:
method - the method name to call.

writeBoolean

public void writeBoolean(boolean value)
            throws IOException
Writes a boolean value to the stream. The boolean will be written with the following syntax:
 T
 F
 
Parameters:
value - the boolean value to write.

writeBytes

public void writeBytes(byte[] buffer)
            throws IOException
Writes a byte array to the stream. The array will be written with the following syntax:
 B b16 b18 bytes
 
If the value is null, it will be written as
 N
 
Parameters:

writeBytes

public void writeBytes(byte[] buffer,
                       int offset,
                       int length)
            throws IOException
Writes a byte array to the stream. The array will be written with the following syntax:
 B b16 b18 bytes
 
If the value is null, it will be written as
 N
 
Parameters:

writeCustomObject

public void writeCustomObject(Object object)
            throws IOException
Applications which override this can do custom serialization.
Parameters:
object - the object to write.

writeInt

public void writeInt(int value)
            throws IOException
Writes an integer value to the stream. The integer will be written with the following syntax:
 I b32 b24 b16 b8
 
Parameters:
value - the integer value to write.

writeListBegin

public void writeListBegin(int length,
                           String type)
            throws 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>
 

writeListEnd

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

writeLong

public void writeLong(long value)
            throws IOException
Writes a long value to the stream. The long will be written with the following syntax:
 L b64 b56 b48 b40 b32 b24 b16 b8
 
Parameters:
value - the long value to write.

writeMapBegin

public void writeMapBegin(String type)
            throws IOException
Writes the map header to the stream. Map writers will call writeMapBegin followed by the map contents and then call writeMapEnd.
 Mt b16 b8 type ( )z
 

writeMapEnd

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

writeNull

public void writeNull()
            throws IOException
Writes a null value to the stream. The null will be written with the following syntax
 N
 
Parameters:

writeObject

public void writeObject(Object object)
            throws IOException
Writes a generic object to the output stream.

writeRef

public void writeRef(int value)
            throws IOException
Writes a reference.
 R b32 b24 b16 b8
 
Parameters:
value - the integer value to write.

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.
 'r' 't' b16 b8 type url
 

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:
 S b16 b8 string-value
 
If the value is null, it will be written as
 N
 
Parameters:
value - the string value to write.

writeUTCDate

public void writeUTCDate(long time)
            throws IOException
Writes a date to the stream.
 T  b64 b56 b48 b40 b32 b24 b16 b8
 
Parameters:
time - the date in milliseconds from the epoch in UTC