Package com.caucho.hessian.io
Class Hessian2Output
java.lang.Object
com.caucho.hessian.io.AbstractHessianOutput
com.caucho.hessian.io.Hessian2Output
- All Implemented Interfaces:
Hessian2Constants
- Direct Known Subclasses:
HessianSerializerOutput
Output stream for Hessian 2 requests.
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 Hessian2Output(os); String value; out.startCall("hello", 1); // start hello call out.writeString("arg1"); // write a string argument out.completeCall(); // complete the call
-
Field Summary
FieldsFields inherited from class com.caucho.hessian.io.AbstractHessianOutput
_serializerFactory
Fields inherited from interface com.caucho.hessian.io.Hessian2Constants
BC_BINARY, BC_BINARY_CHUNK, BC_BINARY_DIRECT, BC_BINARY_SHORT, BC_CLASS_DEF, BC_DATE, BC_DATE_MINUTE, BC_DOUBLE, BC_DOUBLE_BYTE, BC_DOUBLE_MILL, BC_DOUBLE_ONE, BC_DOUBLE_SHORT, BC_DOUBLE_ZERO, BC_END, BC_FALSE, BC_INT, BC_INT_BYTE_ZERO, BC_INT_SHORT_ZERO, BC_INT_ZERO, BC_LIST_DIRECT, BC_LIST_DIRECT_UNTYPED, BC_LIST_FIXED, BC_LIST_FIXED_UNTYPED, BC_LIST_VARIABLE, BC_LIST_VARIABLE_UNTYPED, BC_LONG, BC_LONG_BYTE_ZERO, BC_LONG_INT, BC_LONG_SHORT_ZERO, BC_LONG_ZERO, BC_MAP, BC_MAP_UNTYPED, BC_NULL, BC_OBJECT, BC_OBJECT_DEF, BC_OBJECT_DIRECT, BC_REF, BC_STRING, BC_STRING_CHUNK, BC_STRING_DIRECT, BC_STRING_SHORT, BC_TRUE, BINARY_DIRECT_MAX, BINARY_SHORT_MAX, INT_BYTE_MAX, INT_BYTE_MIN, INT_DIRECT_MAX, INT_DIRECT_MIN, INT_SHORT_MAX, INT_SHORT_MIN, LIST_DIRECT_MAX, LONG_BYTE_MAX, LONG_BYTE_MIN, LONG_DIRECT_MAX, LONG_DIRECT_MIN, LONG_SHORT_MAX, LONG_SHORT_MIN, OBJECT_DIRECT_MAX, P_PACKET, P_PACKET_CHUNK, P_PACKET_DIRECT, P_PACKET_SHORT, PACKET_DIRECT_MAX, PACKET_SHORT_MAX, STRING_DIRECT_MAX, STRING_SHORT_MAX
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Hessian output stream, initialized with an underlying output stream.Creates a new Hessian output stream, initialized with an underlying output stream. -
Method Summary
Modifier and TypeMethodDescriptionboolean
If the object has already been written, just write its ref.void
Writes a complete method call.void
close()
void
Completes.void
Completes an envelope.void
Completes reading the messagevoid
Completes reading the replyvoid
final void
flush()
final void
void
free()
Returns an output stream to write binary data.int
void
init
(OutputStream os) Initialize the output with a new underlying stream.void
boolean
void
Prints a string to the stream, encoded as UTF-8 with preceeding lengthvoid
printString
(char[] v, int strOffset, int length) Prints a string to the stream, encoded as UTF-8void
Prints a string to the stream, encoded as UTF-8void
printString
(String v, int strOffset, int length) Prints a string to the stream, encoded as UTF-8boolean
Removes a reference.boolean
replaceRef
(Object oldRef, Object newRef) Replaces a reference from one object to another.void
reset()
Resets all counters and referencesvoid
Resets the references for streaming.void
setCloseStreamOnClose
(boolean isClose) boolean
setUnshared
(boolean isUnshared) Sets hessian to be "unshared", meaning it will not detect duplicate or circular references.void
Writes the call tag.void
Starts the method call.void
startEnvelope
(String method) Starts an envelope.void
Starts a packetvoid
Starts a streaming packetvoid
Starts the replyvoid
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
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
Writes a full output 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
(String code, String message, Object detail) Writes a fault.void
writeInt
(int value) Writes an integer value to the stream.boolean
writeListBegin
(int length, String type) Writes the list header to the stream.void
Writes the tail of the list to the stream for a variable-length list.void
writeLong
(long value) Writes a long value to the stream.void
writeMapBegin
(String type) Writes the map header to the stream.void
Writes the tail of the map to the stream.void
writeMethod
(String method) Writes the method tag.void
Writes a null value to the stream.void
writeObject
(Object object) Writes any object to the output stream.int
writeObjectBegin
(String type) Writes the object definitionvoid
Writes the tail of the object definition to the stream.protected void
writeRef
(int value) Writes a reference.void
Starts the streaming messagevoid
writeString
(char[] buffer, int offset, int length) Writes a string value to the stream using UTF-8 encoding.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.void
Methods inherited from class com.caucho.hessian.io.AbstractHessianOutput
findSerializerFactory, getSerializerFactory, setSerializerFactory, writeHeader, writeReply
-
Field Details
-
SIZE
public static final int SIZE- See Also:
-
_os
-
-
Constructor Details
-
Hessian2Output
public Hessian2Output()Creates a new Hessian output stream, initialized with an underlying output stream.- Parameters:
os
- the underlying output stream.
-
Hessian2Output
Creates a new Hessian output stream, initialized with an underlying output stream.- Parameters:
os
- the underlying output stream.
-
-
Method Details
-
init
Description copied from class:AbstractHessianOutput
Initialize the output with a new underlying stream.- Overrides:
init
in classAbstractHessianOutput
-
initPacket
-
setCloseStreamOnClose
public void setCloseStreamOnClose(boolean isClose) -
isCloseStreamOnClose
public boolean isCloseStreamOnClose() -
call
Writes a complete method call.- Overrides:
call
in classAbstractHessianOutput
- Throws:
IOException
-
startCall
Starts the method call. Clients would usestartCall
instead ofcall
if they wanted finer control over writing the arguments, or needed to write headers.C string # method name int # arg count
- Specified by:
startCall
in classAbstractHessianOutput
- Parameters:
method
- the method name to call.- Throws:
IOException
-
startCall
Writes the call tag. This would be followed by the method and the argumentsC
- Specified by:
startCall
in classAbstractHessianOutput
- Parameters:
method
- the method name to call.- Throws:
IOException
-
startEnvelope
Starts an envelope.E major minor m b16 b8 method-name
- Parameters:
method
- the method name to call.- Throws:
IOException
-
completeEnvelope
Completes an envelope.A successful completion will have a single value:
Z
- Throws:
IOException
-
writeMethod
Writes the method tag.string
- Specified by:
writeMethod
in classAbstractHessianOutput
- Parameters:
method
- the method name to call.- Throws:
IOException
-
completeCall
Completes.z
- Specified by:
completeCall
in classAbstractHessianOutput
- Throws:
IOException
-
startReply
Starts the replyA successful completion will have a single value:
R
- Overrides:
startReply
in classAbstractHessianOutput
- Throws:
IOException
-
writeVersion
- Throws:
IOException
-
completeReply
Completes reading the replyA successful completion will have a single value:
z
- Overrides:
completeReply
in classAbstractHessianOutput
- Throws:
IOException
-
startMessage
Starts a packetA message contains several objects encapsulated by a length
p x02 x00
- Throws:
IOException
-
completeMessage
Completes reading the messageA successful completion will have a single value:
z
- Throws:
IOException
-
writeFault
Writes a fault. The fault will be written as a descriptive string followed by an object:F map
F H \x04code \x10the fault code \x07message \x11the fault message \x06detail M\xnnjavax.ejb.FinderException ... Z Z
- Overrides:
writeFault
in classAbstractHessianOutput
- Parameters:
code
- the fault code, a three digit- Throws:
IOException
-
writeObject
Writes any object to the output stream.- Specified by:
writeObject
in classAbstractHessianOutput
- Throws:
IOException
-
writeListBegin
Writes the list header to the stream. List writers will callwriteListBegin
followed by the list contents and then callwriteListEnd
.list ::= V type value* Z ::= v type int value*
- Specified by:
writeListBegin
in classAbstractHessianOutput
- Returns:
- true for variable lists, false for fixed lists
- Throws:
IOException
-
writeListEnd
Writes the tail of the list to the stream for a variable-length list.- Specified by:
writeListEnd
in classAbstractHessianOutput
- Throws:
IOException
-
writeMapBegin
Writes the map header to the stream. Map writers will callwriteMapBegin
followed by the map contents and then callwriteMapEnd
.map ::= M type (
)* Z ::= H ( )* Z - Specified by:
writeMapBegin
in classAbstractHessianOutput
- Throws:
IOException
-
writeMapEnd
Writes the tail of the map to the stream.- Specified by:
writeMapEnd
in classAbstractHessianOutput
- Throws:
IOException
-
writeObjectBegin
Writes the object definitionC <string> <int> <string>*
- Overrides:
writeObjectBegin
in classAbstractHessianOutput
- Returns:
- true if the object has already been defined.
- Throws:
IOException
-
writeClassFieldLength
Writes the tail of the class definition to the stream.- Overrides:
writeClassFieldLength
in classAbstractHessianOutput
- Throws:
IOException
-
writeObjectEnd
Writes the tail of the object definition to the stream.- Overrides:
writeObjectEnd
in classAbstractHessianOutput
- Throws:
IOException
-
writeBoolean
Writes a boolean value to the stream. The boolean will be written with the following syntax:T F
- Specified by:
writeBoolean
in classAbstractHessianOutput
- Parameters:
value
- the boolean value to write.- Throws:
IOException
-
writeInt
Writes an integer value to the stream. The integer will be written with the following syntax:I b32 b24 b16 b8
- Specified by:
writeInt
in classAbstractHessianOutput
- Parameters:
value
- the integer value to write.- Throws:
IOException
-
writeLong
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
- Specified by:
writeLong
in classAbstractHessianOutput
- Parameters:
value
- the long value to write.- Throws:
IOException
-
writeDouble
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
- Specified by:
writeDouble
in classAbstractHessianOutput
- Parameters:
value
- the double value to write.- Throws:
IOException
-
writeUTCDate
Writes a date to the stream.date ::= d b7 b6 b5 b4 b3 b2 b1 b0 ::= x65 b3 b2 b1 b0
- Specified by:
writeUTCDate
in classAbstractHessianOutput
- Parameters:
time
- the date in milliseconds from the epoch in UTC- Throws:
IOException
-
writeNull
Writes a null value to the stream. The null will be written with the following syntaxN
- Specified by:
writeNull
in classAbstractHessianOutput
- Parameters:
value
- the string value to write.- Throws:
IOException
-
writeString
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 asS b16 b8 string-value
N
- Specified by:
writeString
in classAbstractHessianOutput
- Parameters:
value
- the string value to write.- Throws:
IOException
-
writeString
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 asS b16 b8 string-value
N
- Specified by:
writeString
in classAbstractHessianOutput
- Parameters:
value
- the string value to write.- Throws:
IOException
-
writeBytes
Writes a byte array to the stream. The array will be written with the following syntax:
If the value is null, it will be written asB b16 b18 bytes
N
- Specified by:
writeBytes
in classAbstractHessianOutput
- Parameters:
value
- the string value to write.- Throws:
IOException
-
writeBytes
Writes a byte array to the stream. The array will be written with the following syntax:
If the value is null, it will be written asB b16 b18 bytes
N
- Specified by:
writeBytes
in classAbstractHessianOutput
- Parameters:
value
- the string value to write.- Throws:
IOException
-
writeByteBufferStart
Writes a byte buffer to the stream.- Specified by:
writeByteBufferStart
in classAbstractHessianOutput
- Throws:
IOException
-
writeByteBufferPart
Writes a byte buffer to the stream.b b16 b18 bytes
- Specified by:
writeByteBufferPart
in classAbstractHessianOutput
- Throws:
IOException
-
writeByteBufferEnd
Writes a byte buffer to the stream.b b16 b18 bytes
- Specified by:
writeByteBufferEnd
in classAbstractHessianOutput
- Throws:
IOException
-
getBytesOutputStream
Returns an output stream to write binary data.- Throws:
IOException
-
writeByteStream
Writes a full output stream.- Overrides:
writeByteStream
in classAbstractHessianOutput
- Throws:
IOException
-
writeRef
Writes a reference.x51 <int>
- Specified by:
writeRef
in classAbstractHessianOutput
- Parameters:
value
- the integer value to write.- Throws:
IOException
-
addRef
If the object has already been written, just write its ref.- Specified by:
addRef
in classAbstractHessianOutput
- Parameters:
object
- the object to add as a reference.- Returns:
- true if we're writing a ref.
- Throws:
IOException
-
getRef
- Specified by:
getRef
in classAbstractHessianOutput
- Returns:
-
removeRef
Removes a reference.- Overrides:
removeRef
in classAbstractHessianOutput
- Throws:
IOException
-
replaceRef
Replaces a reference from one object to another.- Specified by:
replaceRef
in classAbstractHessianOutput
- Throws:
IOException
-
writeStreamingObject
Starts the streaming messageA streaming message starts with 'P'
P x02 x00
- Throws:
IOException
-
startPacket
Starts a streaming packetA streaming contains a set of chunks, ending with a zero chunk. Each chunk is a length followed by data where the length is encoded by (b1xxxxxxxx)* b0xxxxxxxx
- Throws:
IOException
-
endPacket
- Throws:
IOException
-
printLenString
Prints a string to the stream, encoded as UTF-8 with preceeding length- Parameters:
v
- the string to print.- Throws:
IOException
-
printString
Prints a string to the stream, encoded as UTF-8- Parameters:
v
- the string to print.- Throws:
IOException
-
printString
Prints a string to the stream, encoded as UTF-8- Parameters:
v
- the string to print.- Throws:
IOException
-
printString
Prints a string to the stream, encoded as UTF-8- Parameters:
v
- the string to print.- Throws:
IOException
-
flush
- Overrides:
flush
in classAbstractHessianOutput
- Throws:
IOException
-
flushBuffer
- Throws:
IOException
-
close
- Overrides:
close
in classAbstractHessianOutput
- Throws:
IOException
-
free
public void free() -
resetReferences
public void resetReferences()Resets the references for streaming.- Overrides:
resetReferences
in classAbstractHessianOutput
-
reset
public void reset()Resets all counters and references
-