com.caucho.hessian.io
Class HessianInput

java.lang.Object
  extended by com.caucho.hessian.io.AbstractHessianInput
      extended by com.caucho.hessian.io.HessianInput

public class HessianInput
extends AbstractHessianInput

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
protected  int _peek
           
protected  ArrayList _refs
           
protected  SerializerFactory _serializerFactory
           
 
Constructor Summary
HessianInput()
          Creates an uninitialized Hessian input stream.
HessianInput(InputStream is)
          Creates a new Hessian input stream, initialized with an underlying input stream.
 
Method Summary
 int addRef(Object ref)
          Adds a list/map reference.
 void close()
           
protected  String codeName(int ch)
           
 void completeCall()
          Completes reading the call A successful completion will have a single value: z
 void completeReply()
          Completes reading the call A successful completion will have a single value: z
 void completeValueReply()
          Completes reading the call A successful completion will have a single value: z
protected  IOException error(String message)
           
protected  IOException expect(String expect, int ch)
           
 String getMethod()
          Returns the calls method
 Reader getReader()
          Starts reading a string.
 Throwable getReplyFault()
          Returns any reply fault.
 SerializerFactory getSerializerFactory()
          Gets the serializer factory.
 void init(InputStream is)
          Initialize the hessian stream with the underlying input stream.
 boolean isEnd()
          Returns true if this is the end of a list or a map.
 boolean readBoolean()
          Reads a boolean T F
 int readByte()
          Reads a byte from the stream.
 byte[] readBytes()
          Reads a byte array B b16 b8 data value
 int readBytes(byte[] buffer, int offset, int length)
          Reads a byte array from the stream.
 int readCall()
          Starts reading the call c major minor
 int readChar()
          Reads a byte from the stream.
 double readDouble()
          Reads a double D b64 b56 b48 b40 b32 b24 b16 b8
 void readEnd()
          Reads the end byte.
 float readFloat()
          Reads a float D b64 b56 b48 b40 b32 b24 b16 b8
 String readHeader()
          Reads a header, returning null if there are no headers.
 InputStream readInputStream()
          Reads bytes based on an input stream.
 int readInt()
          Reads an integer I b32 b24 b16 b8
 int readLength()
          Parses the length for an array l b32 b24 b16 b8
 void readListEnd()
          Reads the end byte.
 int readListStart()
          Reads the start of a list.
 long readLong()
          Reads a long L b64 b56 b48 b40 b32 b24 b16 b8
 void readMapEnd()
          Reads the end byte.
 int readMapStart()
          Reads the start of a list.
 String readMethod()
          Starts reading the call A successful completion will have a single value: m b16 b8 method
 Node readNode()
          Reads an XML node.
 void readNull()
          Reads a null N
 Object readObject()
          Reads an arbitrary object from the input stream when the type is unknown.
 Object readObject(Class cl)
          Reads an object from the input stream with an expected type.
 Object readRef()
          Reads a reference.
 Object readRemote()
          Reads a remote object.
 Object readReply(Class expectedClass)
          Reads a reply as an object.
 short readShort()
          Reads a short I b32 b24 b16 b8
 String readString()
          Reads a string S b16 b8 string value
 int readString(char[] buffer, int offset, int length)
          Reads a byte array from the stream.
 String readType()
          Parses a type from the stream.
 long readUTCDate()
          Reads a date.
 void resetReferences()
          Resets the references for streaming.
 Object resolveRemote(String type, String url)
          Resolves a remote object.
 void setRef(int i, Object ref)
          Adds a list/map reference.
 void setSerializerFactory(SerializerFactory factory)
          Sets the serializer factory.
 void skipOptionalCall()
          For backward compatibility with HessianSkeleton
 void startCall()
          Starts reading the call, including the headers.
 void startReply()
          Starts reading the reply A successful completion will have a single value: r
 void startReplyBody()
          Starts reading the body of the reply, i.e. after the 'r' has been parsed.
 
Methods inherited from class com.caucho.hessian.io.AbstractHessianInput
getRemoteResolver, readMethodArgLength, readToOutputStream, setRemoteResolver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_serializerFactory

protected SerializerFactory _serializerFactory

_refs

protected ArrayList _refs

_peek

protected int _peek
Constructor Detail

HessianInput

public HessianInput()
Creates an uninitialized Hessian input stream.


HessianInput

public HessianInput(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:
setSerializerFactory in class AbstractHessianInput

getSerializerFactory

public SerializerFactory getSerializerFactory()
Gets the serializer factory.


init

public void init(InputStream is)
Initialize the hessian stream with the underlying input stream.

Overrides:
init in class AbstractHessianInput

getMethod

public String getMethod()
Returns the calls method

Specified by:
getMethod in class AbstractHessianInput

getReplyFault

public Throwable getReplyFault()
Returns any reply fault.


readCall

public int readCall()
             throws IOException
Starts reading the call
 c major minor
 

Specified by:
readCall in class AbstractHessianInput
Throws:
IOException

skipOptionalCall

public void skipOptionalCall()
                      throws IOException
For backward compatibility with HessianSkeleton

Overrides:
skipOptionalCall in class AbstractHessianInput
Throws:
IOException

readMethod

public String readMethod()
                  throws IOException
Starts reading the call

A successful completion will have a single value:

 m b16 b8 method
 

Specified by:
readMethod in class AbstractHessianInput
Throws:
IOException

startCall

public void startCall()
               throws IOException
Starts reading the call, including the headers.

The call expects the following protocol data

 c major minor
 m b16 b8 method
 

Specified by:
startCall in class AbstractHessianInput
Throws:
IOException

completeCall

public void completeCall()
                  throws IOException
Completes reading the call

A successful completion will have a single value:

 z
 

Specified by:
completeCall in class AbstractHessianInput
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:
readReply in class AbstractHessianInput
Throws:
Throwable

startReply

public void startReply()
                throws Throwable
Starts reading the reply

A successful completion will have a single value:

 r
 

Specified by:
startReply in class AbstractHessianInput
Throws:
Throwable

startReplyBody

public void startReplyBody()
                    throws Throwable
Description copied from class: AbstractHessianInput
Starts reading the body of the reply, i.e. after the 'r' has been parsed.

Overrides:
startReplyBody in class AbstractHessianInput
Throws:
Throwable

completeReply

public void completeReply()
                   throws IOException
Completes reading the call

A successful completion will have a single value:

 z
 

Specified by:
completeReply in class AbstractHessianInput
Throws:
IOException

completeValueReply

public void completeValueReply()
                        throws IOException
Completes reading the call

A 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:
readHeader in class AbstractHessianInput
Throws:
IOException

readNull

public void readNull()
              throws IOException
Reads a null
 N
 

Specified by:
readNull in class AbstractHessianInput
Throws:
IOException

readBoolean

public boolean readBoolean()
                    throws IOException
Reads a boolean
 T
 F
 

Specified by:
readBoolean in class AbstractHessianInput
Throws:
IOException

readShort

public short readShort()
                throws IOException
Reads a short
 I b32 b24 b16 b8
 

Throws:
IOException

readInt

public int readInt()
            throws IOException
Reads an integer
 I b32 b24 b16 b8
 

Specified by:
readInt in class AbstractHessianInput
Throws:
IOException

readLong

public long readLong()
              throws IOException
Reads a long
 L b64 b56 b48 b40 b32 b24 b16 b8
 

Specified by:
readLong in class AbstractHessianInput
Throws:
IOException

readFloat

public float readFloat()
                throws IOException
Reads a float
 D b64 b56 b48 b40 b32 b24 b16 b8
 

Throws:
IOException

readDouble

public double readDouble()
                  throws IOException
Reads a double
 D b64 b56 b48 b40 b32 b24 b16 b8
 

Specified by:
readDouble in class AbstractHessianInput
Throws:
IOException

readUTCDate

public long readUTCDate()
                 throws IOException
Reads a date.
 T b64 b56 b48 b40 b32 b24 b16 b8
 

Specified by:
readUTCDate in class AbstractHessianInput
Throws:
IOException

readChar

public int readChar()
             throws IOException
Reads a byte from the stream.

Throws:
IOException

readString

public int readString(char[] buffer,
                      int offset,
                      int length)
               throws IOException
Reads a byte array from the stream.

Throws:
IOException

readString

public String readString()
                  throws IOException
Reads a string
 S b16 b8 string value
 

Specified by:
readString in class AbstractHessianInput
Throws:
IOException

readNode

public Node readNode()
              throws IOException
Reads an XML node.
 S b16 b8 string value
 

Overrides:
readNode in class AbstractHessianInput
Throws:
IOException

readBytes

public byte[] readBytes()
                 throws IOException
Reads a byte array
 B b16 b8 data value
 

Specified by:
readBytes in class AbstractHessianInput
Throws:
IOException

readByte

public int readByte()
             throws IOException
Reads a byte from the stream.

Throws:
IOException

readBytes

public int readBytes(byte[] buffer,
                     int offset,
                     int length)
              throws IOException
Reads 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:
readObject in class AbstractHessianInput
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:
readObject in class AbstractHessianInput
Throws:
IOException

readRemote

public Object readRemote()
                  throws IOException
Reads a remote object.

Specified by:
readRemote in class AbstractHessianInput
Throws:
IOException

readRef

public Object readRef()
               throws IOException
Reads a reference.

Specified by:
readRef in class AbstractHessianInput
Throws:
IOException

readListStart

public int readListStart()
                  throws IOException
Reads the start of a list.

Specified by:
readListStart in class AbstractHessianInput
Throws:
IOException

readMapStart

public int readMapStart()
                 throws IOException
Reads the start of a list.

Specified by:
readMapStart in class AbstractHessianInput
Throws:
IOException

isEnd

public boolean isEnd()
              throws IOException
Returns true if this is the end of a list or a map.

Specified by:
isEnd in class AbstractHessianInput
Throws:
IOException

readEnd

public void readEnd()
             throws IOException
Reads the end byte.

Specified by:
readEnd in class AbstractHessianInput
Throws:
IOException

readMapEnd

public void readMapEnd()
                throws IOException
Reads the end byte.

Specified by:
readMapEnd in class AbstractHessianInput
Throws:
IOException

readListEnd

public void readListEnd()
                 throws IOException
Reads the end byte.

Specified by:
readListEnd in class AbstractHessianInput
Throws:
IOException

addRef

public int addRef(Object ref)
Adds a list/map reference.

Specified by:
addRef in class AbstractHessianInput

setRef

public void setRef(int i,
                   Object ref)
Adds a list/map reference.

Specified by:
setRef in class AbstractHessianInput

resetReferences

public void resetReferences()
Resets the references for streaming.

Overrides:
resetReferences in class AbstractHessianInput

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.
 t b16 b8
 

Specified by:
readType in class AbstractHessianInput
Throws:
IOException

readLength

public int readLength()
               throws IOException
Parses the length for an array
 l b32 b24 b16 b8
 

Specified by:
readLength in class AbstractHessianInput
Throws:
IOException

readInputStream

public InputStream readInputStream()
                            throws IOException
Reads bytes based on an input stream.

Specified by:
readInputStream in class AbstractHessianInput
Throws:
IOException

close

public void close()
Overrides:
close in class AbstractHessianInput

getReader

public Reader getReader()
Description copied from class: AbstractHessianInput
Starts 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:
getReader in class AbstractHessianInput

expect

protected IOException expect(String expect,
                             int ch)

codeName

protected String codeName(int ch)

error

protected IOException error(String message)


Copyright © 2013. All Rights Reserved.