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 Hessian2Output(os);
String value;
out.startCall("hello", 1); // start hello call
out.writeString("arg1"); // write a string argument
out.completeCall(); // complete the call
| Modifier and Type | Field and Description |
|---|---|
protected OutputStream |
_os |
static int |
SIZE |
_serializerFactoryBC_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 and Description |
|---|
Hessian2Output()
Creates a new Hessian output stream, initialized with an
underlying output stream.
|
Hessian2Output(OutputStream os)
Creates a new Hessian output stream, initialized with an
underlying output stream.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addRef(Object object)
If the object has already been written, just write its ref.
|
void |
call(String method,
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 |
endPacket() |
void |
flush() |
void |
flushBuffer() |
void |
free() |
OutputStream |
getBytesOutputStream()
Returns an output stream to write binary data.
|
int |
getRef(Object obj) |
void |
init(OutputStream os)
Initialize the output with a new underlying stream.
|
void |
initPacket(OutputStream os) |
boolean |
isCloseStreamOnClose() |
void |
printLenString(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(String v)
Prints a string to the stream, encoded as UTF-8
|
void |
printString(String v,
int strOffset,
int length)
Prints a string to the stream, encoded as UTF-8
|
boolean |
removeRef(Object obj)
Removes a reference.
|
boolean |
replaceRef(Object oldRef,
Object newRef)
Replaces a reference from one object to another.
|
void |
reset()
Resets all counters and references
|
void |
resetReferences()
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 |
startCall()
Writes the call tag.
|
void |
startCall(String method,
int length)
Starts the method call.
|
void |
startEnvelope(String method)
Starts an envelope.
|
void |
startMessage()
Starts a packet
|
void |
startPacket()
Starts a streaming packet
|
void |
startReply()
Starts the 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 |
writeByteStream(InputStream is)
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 |
writeListEnd()
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 |
writeMapEnd()
Writes the tail of the map to the stream.
|
void |
writeMethod(String method)
Writes the method tag.
|
void |
writeNull()
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 definition
|
void |
writeObjectEnd()
Writes the tail of the object definition to the stream.
|
protected void |
writeRef(int value)
Writes a reference.
|
void |
writeStreamingObject(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(String value)
Writes a string value to the stream using UTF-8 encoding.
|
void |
writeUTCDate(long time)
Writes a date to the stream.
|
void |
writeVersion() |
findSerializerFactory, getSerializerFactory, setSerializerFactory, writeHeader, writeReplypublic static final int SIZE
protected OutputStream _os
public Hessian2Output()
os - the underlying output stream.public Hessian2Output(OutputStream os)
os - the underlying output stream.public void init(OutputStream os)
AbstractHessianOutputinit in class AbstractHessianOutputpublic void initPacket(OutputStream os)
public void setCloseStreamOnClose(boolean isClose)
public boolean isCloseStreamOnClose()
public boolean setUnshared(boolean isUnshared)
setUnshared in class AbstractHessianOutputpublic void call(String method, Object[] args) throws IOException
call in class AbstractHessianOutputIOExceptionpublic void startCall(String method, int length) throws IOException
startCall
instead of call if they wanted finer control over
writing the arguments, or needed to write headers.
C
string # method name
int # arg count
startCall in class AbstractHessianOutputmethod - the method name to call.IOExceptionpublic void startCall()
throws IOException
C
startCall in class AbstractHessianOutputmethod - the method name to call.IOExceptionpublic void startEnvelope(String method) throws IOException
E major minor
m b16 b8 method-name
method - the method name to call.IOExceptionpublic void completeEnvelope()
throws IOException
A successful completion will have a single value:
Z
IOExceptionpublic void writeMethod(String method) throws IOException
string
writeMethod in class AbstractHessianOutputmethod - the method name to call.IOExceptionpublic void completeCall()
throws IOException
z
completeCall in class AbstractHessianOutputIOExceptionpublic void startReply()
throws IOException
A successful completion will have a single value:
R
startReply in class AbstractHessianOutputIOExceptionpublic void writeVersion()
throws IOException
IOExceptionpublic void completeReply()
throws IOException
A successful completion will have a single value:
z
completeReply in class AbstractHessianOutputIOExceptionpublic void startMessage()
throws IOException
A message contains several objects encapsulated by a length
p x02 x00
IOExceptionpublic void completeMessage()
throws IOException
A successful completion will have a single value:
z
IOExceptionpublic void writeFault(String code, String message, Object detail) throws IOException
F map
F H
\x04code
\x10the fault code
\x07message
\x11the fault message
\x06detail
M\xnnjavax.ejb.FinderException
...
Z
Z
writeFault in class AbstractHessianOutputcode - the fault code, a three digitIOExceptionpublic void writeObject(Object object) throws IOException
writeObject in class AbstractHessianOutputIOExceptionpublic boolean writeListBegin(int length,
String type)
throws IOException
writeListBegin followed by the list contents and then
call writeListEnd.
list ::= V type value* Z
::= v type int value*
writeListBegin in class AbstractHessianOutputIOExceptionpublic void writeListEnd()
throws IOException
writeListEnd in class AbstractHessianOutputIOExceptionpublic void writeMapBegin(String type) throws IOException
writeMapBegin followed by the map contents and then
call writeMapEnd.
map ::= M type ( )* Z
::= H ( )* Z
writeMapBegin in class AbstractHessianOutputIOExceptionpublic void writeMapEnd()
throws IOException
writeMapEnd in class AbstractHessianOutputIOExceptionpublic int writeObjectBegin(String type) throws IOException
C <string> <int> <string>*
writeObjectBegin in class AbstractHessianOutputIOExceptionpublic void writeClassFieldLength(int len)
throws IOException
writeClassFieldLength in class AbstractHessianOutputIOExceptionpublic void writeObjectEnd()
throws IOException
writeObjectEnd in class AbstractHessianOutputIOExceptionpublic void writeBoolean(boolean value)
throws IOException
T
F
writeBoolean in class AbstractHessianOutputvalue - the boolean value to write.IOExceptionpublic void writeInt(int value)
throws IOException
I b32 b24 b16 b8
writeInt in class AbstractHessianOutputvalue - the integer value to write.IOExceptionpublic void writeLong(long value)
throws IOException
L b64 b56 b48 b40 b32 b24 b16 b8
writeLong in class AbstractHessianOutputvalue - the long value to write.IOExceptionpublic void writeDouble(double value)
throws IOException
D b64 b56 b48 b40 b32 b24 b16 b8
writeDouble in class AbstractHessianOutputvalue - the double value to write.IOExceptionpublic void writeUTCDate(long time)
throws IOException
date ::= d b7 b6 b5 b4 b3 b2 b1 b0
::= x65 b3 b2 b1 b0
writeUTCDate in class AbstractHessianOutputtime - the date in milliseconds from the epoch in UTCIOExceptionpublic void writeNull()
throws IOException
N
writeNull in class AbstractHessianOutputvalue - the string value to write.IOExceptionpublic void writeString(String value) throws IOException
S b16 b8 string-value
If the value is null, it will be written as
N
writeString in class AbstractHessianOutputvalue - the string value to write.IOExceptionpublic void writeString(char[] buffer,
int offset,
int length)
throws IOException
S b16 b8 string-value
If the value is null, it will be written as
N
writeString in class AbstractHessianOutputvalue - the string value to write.IOExceptionpublic void writeBytes(byte[] buffer)
throws IOException
B b16 b18 bytes
If the value is null, it will be written as
N
writeBytes in class AbstractHessianOutputvalue - the string value to write.IOExceptionpublic void writeBytes(byte[] buffer,
int offset,
int length)
throws IOException
B b16 b18 bytes
If the value is null, it will be written as
N
writeBytes in class AbstractHessianOutputvalue - the string value to write.IOExceptionpublic void writeByteBufferStart()
throws IOException
writeByteBufferStart in class AbstractHessianOutputIOExceptionpublic void writeByteBufferPart(byte[] buffer,
int offset,
int length)
throws IOException
b b16 b18 bytes
writeByteBufferPart in class AbstractHessianOutputIOExceptionpublic void writeByteBufferEnd(byte[] buffer,
int offset,
int length)
throws IOException
b b16 b18 bytes
writeByteBufferEnd in class AbstractHessianOutputIOExceptionpublic OutputStream getBytesOutputStream() throws IOException
IOExceptionpublic void writeByteStream(InputStream is) throws IOException
writeByteStream in class AbstractHessianOutputIOExceptionprotected void writeRef(int value)
throws IOException
x51 <int>
writeRef in class AbstractHessianOutputvalue - the integer value to write.IOExceptionpublic boolean addRef(Object object) throws IOException
addRef in class AbstractHessianOutputobject - the object to add as a reference.IOExceptionpublic int getRef(Object obj)
getRef in class AbstractHessianOutputpublic boolean removeRef(Object obj) throws IOException
removeRef in class AbstractHessianOutputIOExceptionpublic boolean replaceRef(Object oldRef, Object newRef) throws IOException
replaceRef in class AbstractHessianOutputIOExceptionpublic void writeStreamingObject(Object obj) throws IOException
A streaming message starts with 'P'
P x02 x00
IOExceptionpublic void startPacket()
throws IOException
A 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
IOExceptionpublic void endPacket()
throws IOException
IOExceptionpublic void printLenString(String v) throws IOException
v - the string to print.IOExceptionpublic void printString(String v) throws IOException
v - the string to print.IOExceptionpublic void printString(String v, int strOffset, int length) throws IOException
v - the string to print.IOExceptionpublic void printString(char[] v,
int strOffset,
int length)
throws IOException
v - the string to print.IOExceptionpublic final void flush()
throws IOException
flush in class AbstractHessianOutputIOExceptionpublic final void flushBuffer()
throws IOException
IOExceptionpublic void close()
throws IOException
close in class AbstractHessianOutputIOExceptionpublic void free()
public void resetReferences()
resetReferences in class AbstractHessianOutputpublic void reset()
Copyright © 2017 Caucho Technology, Inc. All rights reserved.