public class Hessian2Output extends AbstractHessianOutput implements Hessian2Constants
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 Hessian2Output out = new Hessian11Output(os); String value; out.startCall("hello"); // start hello call out.writeString("arg1"); // write a string argument out.completeCall(); // complete the call
Modifier and Type | Class and Description |
---|---|
(package private) class |
Hessian2Output.BytesOutputStream |
Modifier and Type | Field and Description |
---|---|
private byte[] |
_buffer |
private java.util.HashMap |
_classRefs |
private boolean |
_isCloseStreamOnClose |
private boolean |
_isStreaming |
private int |
_offset |
protected java.io.OutputStream |
_os |
private IdentityIntMap |
_refs |
private java.util.HashMap |
_serializerMap |
private java.util.HashMap |
_typeRefs |
private static int |
SIZE |
_serializerFactory
BYTES_DIRECT, BYTES_DIRECT_MAX, DOUBLE_BYTE, DOUBLE_FLOAT, DOUBLE_ONE, DOUBLE_SHORT, DOUBLE_ZERO, INT_BYTE_MAX, INT_BYTE_MIN, INT_BYTE_ZERO, INT_DIRECT_MAX, INT_DIRECT_MIN, INT_SHORT_MAX, INT_SHORT_MIN, INT_SHORT_ZERO, INT_ZERO, LENGTH_BYTE, LIST_FIXED, LONG_BYTE_MAX, LONG_BYTE_MIN, LONG_BYTE_ZERO, LONG_DIRECT_MAX, LONG_DIRECT_MIN, LONG_INT, LONG_SHORT_MAX, LONG_SHORT_MIN, LONG_SHORT_ZERO, LONG_ZERO, REF_BYTE, REF_SHORT, STRING_DIRECT, STRING_DIRECT_MAX, TYPE_REF
Constructor and Description |
---|
Hessian2Output(java.io.OutputStream os)
Creates a new Hessian output stream, initialized with an
underlying output stream.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addRef(java.lang.Object object)
If the object has already been written, just write its ref.
|
void |
call(java.lang.String method,
java.lang.Object[] args)
Writes a complete method call.
|
void |
close() |
void |
completeCall()
Completes.
|
void |
completeEnvelope()
Completes an envelope.
|
void |
completeMessage()
Completes reading the message
|
void |
completeReply()
Completes reading the reply
|
void |
flush() |
private void |
flushIfFull() |
java.io.OutputStream |
getBytesOutputStream()
Returns an output stream to write binary data.
|
boolean |
isCloseStreamOnClose() |
void |
printLenString(java.lang.String v)
Prints a string to the stream, encoded as UTF-8 with preceeding length
|
void |
printString(char[] v,
int strOffset,
int length)
Prints a string to the stream, encoded as UTF-8
|
void |
printString(java.lang.String v)
Prints a string to the stream, encoded as UTF-8
|
void |
printString(java.lang.String v,
int strOffset,
int length)
Prints a string to the stream, encoded as UTF-8
|
boolean |
removeRef(java.lang.Object obj)
Removes a reference.
|
boolean |
replaceRef(java.lang.Object oldRef,
java.lang.Object newRef)
Replaces a reference from one object to another.
|
void |
resetReferences()
Resets the references for streaming.
|
void |
setCloseStreamOnClose(boolean isClose) |
void |
startCall()
Writes the call tag.
|
void |
startCall(java.lang.String method)
Starts the method call.
|
void |
startEnvelope(java.lang.String method)
Starts an envelope.
|
void |
startMessage()
Starts the message
|
void |
startReply()
Starts the reply
|
void |
startStreamingCall()
Writes the streaming call tag.
|
void |
startStreamingReply()
Starts the streaming reply
|
void |
writeBoolean(boolean value)
Writes a boolean value to the stream.
|
void |
writeByteBufferEnd(byte[] buffer,
int offset,
int length)
Writes a byte buffer to the stream.
|
void |
writeByteBufferPart(byte[] buffer,
int offset,
int length)
Writes a byte buffer to the stream.
|
void |
writeByteBufferStart()
Writes a byte buffer 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 |
writeClassFieldLength(int len)
Writes the tail of the class definition to the stream.
|
void |
writeDouble(double value)
Writes a double value to the stream.
|
void |
writeFault(java.lang.String code,
java.lang.String message,
java.lang.Object detail)
Writes a fault.
|
void |
writeHeader(java.lang.String name)
Writes a header name.
|
void |
writeInt(int value)
Writes an integer value to the stream.
|
boolean |
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 |
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 |
writeMethod(java.lang.String method)
Writes the method tag.
|
void |
writeNull()
Writes a null value to the stream.
|
void |
writeObject(java.lang.Object object)
Writes any object to the output stream.
|
int |
writeObjectBegin(java.lang.String type)
Writes the object definition
|
void |
writeObjectEnd()
Writes the tail of the object definition to the stream.
|
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 |
writeStreamingObject(java.lang.Object obj)
Starts the streaming message
|
void |
writeString(char[] buffer,
int offset,
int length)
Writes a string value to the stream using UTF-8 encoding.
|
void |
writeString(java.lang.String value)
Writes a string value to the stream using UTF-8 encoding.
|
private void |
writeType(java.lang.String type) |
void |
writeUTCDate(long time)
Writes a date to the stream.
|
findSerializerFactory, getSerializerFactory, init, setSerializerFactory
protected java.io.OutputStream _os
private IdentityIntMap _refs
private java.util.HashMap _serializerMap
private boolean _isCloseStreamOnClose
private java.util.HashMap _classRefs
private java.util.HashMap _typeRefs
private static final int SIZE
private final byte[] _buffer
private int _offset
private boolean _isStreaming
public Hessian2Output(java.io.OutputStream os)
os
- the underlying output stream.public void setCloseStreamOnClose(boolean isClose)
public boolean isCloseStreamOnClose()
public void call(java.lang.String method, java.lang.Object[] args) throws java.io.IOException
call
in class AbstractHessianOutput
java.io.IOException
public void startCall(java.lang.String method) throws java.io.IOException
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 class AbstractHessianOutput
method
- the method name to call.java.io.IOException
public void startCall() throws java.io.IOException
c major minor
startCall
in class AbstractHessianOutput
method
- the method name to call.java.io.IOException
public void startStreamingCall() throws java.io.IOException
C major minor
method
- the method name to call.java.io.IOException
public void startEnvelope(java.lang.String method) throws java.io.IOException
E major minor
m b16 b8 method-name
method
- the method name to call.java.io.IOException
public void completeEnvelope() throws java.io.IOException
A successful completion will have a single value:
z
java.io.IOException
public void writeMethod(java.lang.String method) throws java.io.IOException
m b16 b8 method-name
writeMethod
in class AbstractHessianOutput
method
- the method name to call.java.io.IOException
public void completeCall() throws java.io.IOException
z
completeCall
in class AbstractHessianOutput
java.io.IOException
public void startReply() throws java.io.IOException
A successful completion will have a single value:
r
startReply
in class AbstractHessianOutput
java.io.IOException
public void startStreamingReply() throws java.io.IOException
A successful completion will have a single value:
r
java.io.IOException
public void completeReply() throws java.io.IOException
A successful completion will have a single value:
z
completeReply
in class AbstractHessianOutput
java.io.IOException
public void startMessage() throws java.io.IOException
A message contains several objects followed by a 'z'
p x02 x00
java.io.IOException
public void completeMessage() throws java.io.IOException
A successful completion will have a single value:
z
java.io.IOException
public void writeHeader(java.lang.String name) throws java.io.IOException
H b16 b8 foo value
writeHeader
in class AbstractHessianOutput
java.io.IOException
public void writeFault(java.lang.String code, java.lang.String message, java.lang.Object detail) throws java.io.IOException
f
<string>code
<string>the fault code
<string>message
<string>the fault mesage
<string>detail
mt\x00\xnnjavax.ejb.FinderException
...
z
z
writeFault
in class AbstractHessianOutput
code
- the fault code, a three digitjava.io.IOException
public void writeObject(java.lang.Object object) throws java.io.IOException
writeObject
in class AbstractHessianOutput
java.io.IOException
public boolean writeListBegin(int length, java.lang.String type) throws java.io.IOException
writeListBegin
followed by the list contents and then
call writeListEnd
.
V
t b16 b8 type
l b32 b24 b16 b8
writeListBegin
in class AbstractHessianOutput
java.io.IOException
public void writeListEnd() throws java.io.IOException
writeListEnd
in class AbstractHessianOutput
java.io.IOException
public void writeMapBegin(java.lang.String type) throws java.io.IOException
writeMapBegin
followed by the map contents and then
call writeMapEnd
.
Mt b16 b8 ( )z
writeMapBegin
in class AbstractHessianOutput
java.io.IOException
public void writeMapEnd() throws java.io.IOException
writeMapEnd
in class AbstractHessianOutput
java.io.IOException
public int writeObjectBegin(java.lang.String type) throws java.io.IOException
O t b16 b8 *
writeObjectBegin
in class AbstractHessianOutput
java.io.IOException
public void writeClassFieldLength(int len) throws java.io.IOException
writeClassFieldLength
in class AbstractHessianOutput
java.io.IOException
public void writeObjectEnd() throws java.io.IOException
writeObjectEnd
in class AbstractHessianOutput
java.io.IOException
public void writeRemote(java.lang.String type, java.lang.String url) throws java.io.IOException
'r' 't' b16 b8 type url
writeRemote
in class AbstractHessianOutput
java.io.IOException
private void writeType(java.lang.String type) throws java.io.IOException
java.io.IOException
public void writeBoolean(boolean value) throws java.io.IOException
T
F
writeBoolean
in class AbstractHessianOutput
value
- the boolean value to write.java.io.IOException
public void writeInt(int value) throws java.io.IOException
I b32 b24 b16 b8
writeInt
in class AbstractHessianOutput
value
- the integer value to write.java.io.IOException
public void writeLong(long value) throws java.io.IOException
L b64 b56 b48 b40 b32 b24 b16 b8
writeLong
in class AbstractHessianOutput
value
- the long value to write.java.io.IOException
public void writeDouble(double value) throws java.io.IOException
D b64 b56 b48 b40 b32 b24 b16 b8
writeDouble
in class AbstractHessianOutput
value
- the double value to write.java.io.IOException
public void writeUTCDate(long time) throws java.io.IOException
T b64 b56 b48 b40 b32 b24 b16 b8
writeUTCDate
in class AbstractHessianOutput
time
- the date in milliseconds from the epoch in UTCjava.io.IOException
public void writeNull() throws java.io.IOException
N
writeNull
in class AbstractHessianOutput
value
- the string value to write.java.io.IOException
public void writeString(java.lang.String value) throws java.io.IOException
S b16 b8 string-value
If the value is null, it will be written as
N
writeString
in class AbstractHessianOutput
value
- the string value to write.java.io.IOException
public void writeString(char[] buffer, int offset, int length) throws java.io.IOException
S b16 b8 string-value
If the value is null, it will be written as
N
writeString
in class AbstractHessianOutput
value
- the string value to write.java.io.IOException
public void writeBytes(byte[] buffer) throws java.io.IOException
B b16 b18 bytes
If the value is null, it will be written as
N
writeBytes
in class AbstractHessianOutput
value
- the string value to write.java.io.IOException
public void writeBytes(byte[] buffer, int offset, int length) throws java.io.IOException
B b16 b18 bytes
If the value is null, it will be written as
N
writeBytes
in class AbstractHessianOutput
value
- the string value to write.java.io.IOException
public void writeByteBufferStart() throws java.io.IOException
writeByteBufferStart
in class AbstractHessianOutput
java.io.IOException
public void writeByteBufferPart(byte[] buffer, int offset, int length) throws java.io.IOException
b b16 b18 bytes
writeByteBufferPart
in class AbstractHessianOutput
java.io.IOException
public void writeByteBufferEnd(byte[] buffer, int offset, int length) throws java.io.IOException
b b16 b18 bytes
writeByteBufferEnd
in class AbstractHessianOutput
java.io.IOException
public java.io.OutputStream getBytesOutputStream() throws java.io.IOException
java.io.IOException
public void writeRef(int value) throws java.io.IOException
R b32 b24 b16 b8
writeRef
in class AbstractHessianOutput
value
- the integer value to write.java.io.IOException
public boolean addRef(java.lang.Object object) throws java.io.IOException
addRef
in class AbstractHessianOutput
object
- the object to add as a reference.java.io.IOException
public boolean removeRef(java.lang.Object obj) throws java.io.IOException
removeRef
in class AbstractHessianOutput
java.io.IOException
public boolean replaceRef(java.lang.Object oldRef, java.lang.Object newRef) throws java.io.IOException
replaceRef
in class AbstractHessianOutput
java.io.IOException
public void resetReferences()
resetReferences
in class AbstractHessianOutput
public void writeStreamingObject(java.lang.Object obj) throws java.io.IOException
A streaming message starts with 'P'
P x02 x00
java.io.IOException
public void printLenString(java.lang.String v) throws java.io.IOException
v
- the string to print.java.io.IOException
public void printString(java.lang.String v) throws java.io.IOException
v
- the string to print.java.io.IOException
public void printString(java.lang.String v, int strOffset, int length) throws java.io.IOException
v
- the string to print.java.io.IOException
public void printString(char[] v, int strOffset, int length) throws java.io.IOException
v
- the string to print.java.io.IOException
private final void flushIfFull() throws java.io.IOException
java.io.IOException
public final void flush() throws java.io.IOException
flush
in class AbstractHessianOutput
java.io.IOException
public final void close() throws java.io.IOException
close
in class AbstractHessianOutput
java.io.IOException