Package com.caucho.hessian.io
Class Hessian2Input
- java.lang.Object
-
- com.caucho.hessian.io.AbstractHessianInput
-
- com.caucho.hessian.io.Hessian2Input
-
- All Implemented Interfaces:
Hessian2Constants
- Direct Known Subclasses:
HessianSerializerInput
public class Hessian2Input extends AbstractHessianInput implements Hessian2Constants
Input stream for Hessian requests.HessianInput is unbuffered, so any client needs to provide its own buffering.
InputStream is = ...; // from http connection HessianInput in = new HessianInput(is); String value; in.startReply(); // read reply header value = in.readString(); // read string value in.completeReply(); // read reply footer
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<com.caucho.hessian.io.Hessian2Input.ObjectDefinition>_classDefsprotected SerializerFactory_defaultSerializerFactoryprotected ArrayList<Object>_refsprotected SerializerFactory_serializerFactoryprotected ArrayList<String>_types-
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
Constructors Constructor Description Hessian2Input()Hessian2Input(InputStream is)Creates a new Hessian input stream, initialized with an underlying input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddRef(Object ref)Adds a list/map reference.voidallow(String pattern)voidclose()protected StringcodeName(int ch)voidcompleteCall()Completes reading the callvoidcompleteEnvelope()Completes reading the envelopevoidcompleteMessage()Completes reading the messagevoidcompleteReply()Completes reading the callvoidcompleteValueReply()Completes reading the callprotected IOExceptionerror(String message)protected IOExceptionexpect(String expect, int ch)protected SerializerFactoryfindSerializerFactory()Gets the serializer factory.voidfree()StringgetMethod()Returns the calls methodReadergetReader()Starts reading a string.ThrowablegetReplyFault()Returns any reply fault.SerializerFactorygetSerializerFactory()Gets the serializer factory.voidinit(InputStream is)Initialize the Hessian stream with the underlying input stream.voidinitPacket(InputStream is)booleanisCloseStreamOnClose()booleanisEnd()Returns true if this is the end of a list or a map.intread()Normally, shouldn't be called externally, but needed for QA, e.g.Object[]readArguments()booleanreadBoolean()Reads a booleanintreadByte()Reads a byte from the stream.byte[]readBytes()Reads a byte arrayintreadBytes(byte[] buffer, int offset, int length)Reads a byte array from the stream.intreadCall()Starts reading the callintreadChar()Reads a byte from the stream.doublereadDouble()Reads a doublevoidreadEnd()Reads the end byte.intreadEnvelope()Starts reading the envelopefloatreadFloat()Reads a floatStringreadHeader()Reads a header, returning null if there are no headers.InputStreamreadInputStream()Reads bytes based on an input stream.intreadInt()Reads an integerintreadLength()Parses the length for an arrayvoidreadListEnd()Reads the end byte.intreadListStart()Reads the start of a list.longreadLong()Reads a longvoidreadMapEnd()Reads the end byte.intreadMapStart()Reads the start of a list.StringreadMethod()Starts reading the callintreadMethodArgLength()Returns the number of method argumentsvoidreadNull()Reads a nullObjectreadObject()Reads an arbitrary object from the input stream when the type is unknown.ObjectreadObject(Class cl)Reads an object from the input stream with an expected type.ObjectreadRef()Reads a reference.ObjectreadRemote()Reads a remote object.ObjectreadReply(Class expectedClass)Reads a reply as an object.shortreadShort()Reads a shortObjectreadStreamingObject()StringreadString()Reads a stringintreadString(char[] buffer, int offset, int length)Reads a byte array from the stream.StringreadType()Parses a type from the stream.longreadUTCDate()Reads a date.voidreset()voidresetBuffer()voidresetReferences()Resets the references for streaming.ObjectresolveRemote(String type, String url)Resolves a remote object.voidsetCloseStreamOnClose(boolean isClose)voidsetRef(int i, Object ref)Adds a list/map reference.voidsetSerializerFactory(SerializerFactory factory)Sets the serializer factory.voidstartCall()Starts reading the call, including the headers.intstartMessage()Starts reading a packetvoidstartReply()Starts reading the replyprotected voidunread()-
Methods inherited from class com.caucho.hessian.io.AbstractHessianInput
getRemoteResolver, readNode, readToOutputStream, setRemoteResolver, skipOptionalCall, startReplyBody
-
-
-
-
Field Detail
-
_defaultSerializerFactory
protected SerializerFactory _defaultSerializerFactory
-
_serializerFactory
protected SerializerFactory _serializerFactory
-
_classDefs
protected ArrayList<com.caucho.hessian.io.Hessian2Input.ObjectDefinition> _classDefs
-
-
Constructor Detail
-
Hessian2Input
public Hessian2Input()
-
Hessian2Input
public Hessian2Input(InputStream is)
Creates a new Hessian input stream, initialized with an underlying input stream.- Parameters:
is- the underlying input stream.
-
-
Method Detail
-
setSerializerFactory
public void setSerializerFactory(SerializerFactory factory)
Sets the serializer factory.- Overrides:
setSerializerFactoryin classAbstractHessianInput
-
getSerializerFactory
public SerializerFactory getSerializerFactory()
Gets the serializer factory.
-
findSerializerFactory
protected final SerializerFactory findSerializerFactory()
Gets the serializer factory.
-
allow
public void allow(String pattern)
-
setCloseStreamOnClose
public void setCloseStreamOnClose(boolean isClose)
-
isCloseStreamOnClose
public boolean isCloseStreamOnClose()
-
getMethod
public String getMethod()
Returns the calls method- Specified by:
getMethodin classAbstractHessianInput
-
getReplyFault
public Throwable getReplyFault()
Returns any reply fault.
-
init
public void init(InputStream is)
Description copied from class:AbstractHessianInputInitialize the Hessian stream with the underlying input stream.- Overrides:
initin classAbstractHessianInput
-
initPacket
public void initPacket(InputStream is)
-
readCall
public int readCall() throws IOExceptionStarts reading the callc major minor
- Specified by:
readCallin classAbstractHessianInput- Throws:
IOException
-
readEnvelope
public int readEnvelope() throws IOExceptionStarts reading the envelopeE major minor
- Throws:
IOException
-
completeEnvelope
public void completeEnvelope() throws IOExceptionCompletes reading the envelopeA successful completion will have a single value:
Z
- Throws:
IOException
-
readMethod
public String readMethod() throws IOException
Starts reading the callA successful completion will have a single value:
string
- Specified by:
readMethodin classAbstractHessianInput- Throws:
IOException
-
readMethodArgLength
public int readMethodArgLength() throws IOExceptionReturns the number of method argumentsint
- Overrides:
readMethodArgLengthin classAbstractHessianInput- Returns:
- -1 for a variable length (hessian 1.0)
- Throws:
IOException
-
startCall
public void startCall() throws IOExceptionStarts reading the call, including the headers.The call expects the following protocol data
c major minor m b16 b8 method
- Specified by:
startCallin classAbstractHessianInput- Throws:
IOException
-
readArguments
public Object[] readArguments() throws IOException
- Throws:
IOException
-
completeCall
public void completeCall() throws IOExceptionCompletes reading the callA successful completion will have a single value:
- Specified by:
completeCallin classAbstractHessianInput- Throws:
IOException
-
readReply
public Object readReply(Class expectedClass) throws Throwable
Reads a reply as an object. If the reply has a fault, throws the exception.- Specified by:
readReplyin classAbstractHessianInput- Throws:
Throwable
-
startReply
public void startReply() throws ThrowableStarts reading the replyA successful completion will have a single value:
r
- Specified by:
startReplyin classAbstractHessianInput- Throws:
Throwable
-
completeReply
public void completeReply() throws IOExceptionCompletes reading the callA successful completion will have a single value:
z
- Specified by:
completeReplyin classAbstractHessianInput- Throws:
IOException
-
completeValueReply
public void completeValueReply() throws IOExceptionCompletes reading the callA successful completion will have a single value:
z
- Throws:
IOException
-
readHeader
public String readHeader() throws IOException
Reads a header, returning null if there are no headers.H b16 b8 value
- Specified by:
readHeaderin classAbstractHessianInput- Throws:
IOException
-
startMessage
public int startMessage() throws IOExceptionStarts reading a packetp major minor
- Throws:
IOException
-
completeMessage
public void completeMessage() throws IOExceptionCompletes reading the messageA successful completion will have a single value:
z
- Throws:
IOException
-
readNull
public void readNull() throws IOExceptionReads a nullN
- Specified by:
readNullin classAbstractHessianInput- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOExceptionReads a booleanT F
- Specified by:
readBooleanin classAbstractHessianInput- Throws:
IOException
-
readShort
public short readShort() throws IOExceptionReads a shortI b32 b24 b16 b8
- Throws:
IOException
-
readInt
public final int readInt() throws IOExceptionReads an integerI b32 b24 b16 b8
- Specified by:
readIntin classAbstractHessianInput- Throws:
IOException
-
readLong
public long readLong() throws IOExceptionReads a longL b64 b56 b48 b40 b32 b24 b16 b8
- Specified by:
readLongin classAbstractHessianInput- Throws:
IOException
-
readFloat
public float readFloat() throws IOExceptionReads a floatD b64 b56 b48 b40 b32 b24 b16 b8
- Throws:
IOException
-
readDouble
public double readDouble() throws IOExceptionReads a doubleD b64 b56 b48 b40 b32 b24 b16 b8
- Specified by:
readDoublein classAbstractHessianInput- Throws:
IOException
-
readUTCDate
public long readUTCDate() throws IOExceptionReads a date.T b64 b56 b48 b40 b32 b24 b16 b8
- Specified by:
readUTCDatein classAbstractHessianInput- Throws:
IOException
-
readChar
public int readChar() throws IOExceptionReads a byte from the stream.- Throws:
IOException
-
readString
public int readString(char[] buffer, int offset, int length) throws IOExceptionReads a byte array from the stream.- Throws:
IOException
-
readString
public String readString() throws IOException
Reads a stringS b16 b8 string value
- Specified by:
readStringin classAbstractHessianInput- Throws:
IOException
-
readBytes
public byte[] readBytes() throws IOExceptionReads a byte arrayB b16 b8 data value
- Specified by:
readBytesin classAbstractHessianInput- Throws:
IOException
-
readByte
public int readByte() throws IOExceptionReads a byte from the stream.- Throws:
IOException
-
readBytes
public int readBytes(byte[] buffer, int offset, int length) throws IOExceptionReads a byte array from the stream.- Throws:
IOException
-
readObject
public Object readObject(Class cl) throws IOException
Reads an object from the input stream with an expected type.- Specified by:
readObjectin classAbstractHessianInput- Parameters:
cl- the expected class if the protocol doesn't supply it.- Throws:
IOException
-
readObject
public Object readObject() throws IOException
Reads an arbitrary object from the input stream when the type is unknown.- Specified by:
readObjectin classAbstractHessianInput- Throws:
IOException
-
readRemote
public Object readRemote() throws IOException
Reads a remote object.- Specified by:
readRemotein classAbstractHessianInput- Throws:
IOException
-
readRef
public Object readRef() throws IOException
Reads a reference.- Specified by:
readRefin classAbstractHessianInput- Throws:
IOException
-
readListStart
public int readListStart() throws IOExceptionReads the start of a list.- Specified by:
readListStartin classAbstractHessianInput- Throws:
IOException
-
readMapStart
public int readMapStart() throws IOExceptionReads the start of a list.- Specified by:
readMapStartin classAbstractHessianInput- Throws:
IOException
-
isEnd
public boolean isEnd() throws IOExceptionReturns true if this is the end of a list or a map.- Specified by:
isEndin classAbstractHessianInput- Throws:
IOException
-
readEnd
public void readEnd() throws IOExceptionReads the end byte.- Specified by:
readEndin classAbstractHessianInput- Throws:
IOException
-
readMapEnd
public void readMapEnd() throws IOExceptionReads the end byte.- Specified by:
readMapEndin classAbstractHessianInput- Throws:
IOException
-
readListEnd
public void readListEnd() throws IOExceptionReads the end byte.- Specified by:
readListEndin classAbstractHessianInput- Throws:
IOException
-
addRef
public int addRef(Object ref)
Adds a list/map reference.- Specified by:
addRefin classAbstractHessianInput
-
setRef
public void setRef(int i, Object ref)Adds a list/map reference.- Specified by:
setRefin classAbstractHessianInput
-
resetReferences
public void resetReferences()
Resets the references for streaming.- Overrides:
resetReferencesin classAbstractHessianInput
-
reset
public void reset()
-
resetBuffer
public void resetBuffer()
-
readStreamingObject
public Object readStreamingObject() throws IOException
- Throws:
IOException
-
resolveRemote
public Object resolveRemote(String type, String url) throws IOException
Resolves a remote object.- Throws:
IOException
-
readType
public String readType() throws IOException
Parses a type from the stream.type ::= string type ::= int
- Specified by:
readTypein classAbstractHessianInput- Throws:
IOException
-
readLength
public int readLength() throws IOExceptionParses the length for an arrayl b32 b24 b16 b8
- Specified by:
readLengthin classAbstractHessianInput- Throws:
IOException
-
readInputStream
public InputStream readInputStream() throws IOException
Reads bytes based on an input stream.- Specified by:
readInputStreamin classAbstractHessianInput- Throws:
IOException
-
read
public final int read() throws IOExceptionNormally, shouldn't be called externally, but needed for QA, e.g. ejb/3b01.- Throws:
IOException
-
unread
protected void unread()
-
getReader
public Reader getReader()
Description copied from class:AbstractHessianInputStarts reading a string. All the characters must be read before calling the next method. The actual characters will be read with the reader's read() or read(char [], int, int).s b16 b8 non-final string chunk S b16 b8 final string chunk
- Specified by:
getReaderin classAbstractHessianInput
-
expect
protected IOException expect(String expect, int ch) throws IOException
- Throws:
IOException
-
codeName
protected String codeName(int ch)
-
error
protected IOException error(String message)
-
free
public void free()
-
close
public void close() throws IOException- Overrides:
closein classAbstractHessianInput- Throws:
IOException
-
-