Output stream for Hessian requests, compatible with microedition
Java. It only uses classes and types available in JDK.
Since HessianOutput does not depend on any classes other than
in the JDK, it can be extracted independently into a smaller package.
HessianOutput is unbuffered, so any client needs to provide
its own buffering.
OutputStream os = ...; // from http connection
HessianOutput out = new HessianOutput(os);
String value;
out.startCall("hello"); // start hello call
out.writeString("arg1"); // write a string argument
out.completeCall(); // complete the call
addRef
public boolean addRef(Object object)
throws IOException
If the object has already been written, just write its ref.
- addRef in interface AbstractHessianOutput
- true if we're writing a ref.
call
public void call(String method,
Object[] args)
throws IOException
Writes a complete method call.
completeReply
public void completeReply()
throws IOException
Completes reading the reply
A successful completion will have a single value:
z
printLenString
public void printLenString(String v)
throws IOException
Prints a string to the stream, encoded as UTF-8 with preceeding length
printString
public void printString(String v)
throws IOException
Prints a string to the stream, encoded as UTF-8
printString
public void printString(String v,
int offset,
int length)
throws IOException
Prints a string to the stream, encoded as UTF-8
printString
public void printString(char[] v,
int offset,
int length)
throws IOException
Prints a string to the stream, encoded as UTF-8
replaceRef
public boolean replaceRef(Object oldRef,
Object newRef)
throws IOException
Replaces a reference from one object to another.
- replaceRef in interface AbstractHessianOutput
startCall
public void startCall(String method)
throws IOException
Starts the method call. Clients would use
startCall
instead of
call
if they wanted finer control over
writing the arguments, or needed to write headers.
c major minor
m b16 b8 method-name
- startCall in interface AbstractHessianOutput
method
- the method name to call.
startReply
public void startReply()
throws IOException
Starts the reply
A successful completion will have a single value:
r
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
- writeBoolean in interface AbstractHessianOutput
value
- the boolean value to write.
writeByteBufferEnd
public void writeByteBufferEnd(byte[] buffer,
int offset,
int length)
throws IOException
Writes a byte buffer to the stream.
b b16 b18 bytes
- writeByteBufferEnd in interface AbstractHessianOutput
writeByteBufferPart
public void writeByteBufferPart(byte[] buffer,
int offset,
int length)
throws IOException
Writes a byte buffer to the stream.
b b16 b18 bytes
- writeByteBufferPart in interface AbstractHessianOutput
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
- writeBytes in interface AbstractHessianOutput
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
- writeBytes in interface AbstractHessianOutput
writeDouble
public void writeDouble(double value)
throws IOException
Writes a double value to the stream. The double will be written
with the following syntax:
D b64 b56 b48 b40 b32 b24 b16 b8
- writeDouble in interface AbstractHessianOutput
value
- the double value to write.
writeFault
public void writeFault(String code,
String message,
Object detail)
throws IOException
Writes a fault. The fault will be written
as a descriptive string followed by an object:
f
<string>code
<string>the fault code
<string>message
<string>the fault mesage
<string>detail
mt\x00\xnnjavax.ejb.FinderException
...
z
z
code
- the fault code, a three digit
writeHeader
public void writeHeader(String name)
throws IOException
Writes a header name. The header value must immediately follow.
H b16 b8 foo value
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
- writeInt in interface AbstractHessianOutput
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
.
V
t b16 b8 type
l b32 b24 b16 b8
- writeListBegin in interface AbstractHessianOutput
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
- writeLong in interface AbstractHessianOutput
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 ( )z
- writeMapBegin in interface AbstractHessianOutput
writeNull
public void writeNull()
throws IOException
Writes a null value to the stream.
The null will be written with the following syntax
N
- writeNull in interface AbstractHessianOutput
writePlaceholder
public void writePlaceholder()
throws IOException
writeRef
public void writeRef(int value)
throws IOException
Writes a reference.
R b32 b24 b16 b8
- writeRef in interface AbstractHessianOutput
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
- writeRemote in interface AbstractHessianOutput
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
- writeString in interface AbstractHessianOutput
value
- the string value to write.
writeString
public void writeString(char[] buffer,
int offset,
int length)
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
- writeString in interface AbstractHessianOutput
writeUTCDate
public void writeUTCDate(long time)
throws IOException
Writes a date to the stream.
T b64 b56 b48 b40 b32 b24 b16 b8
- writeUTCDate in interface AbstractHessianOutput
time
- the date in milliseconds from the epoch in UTC