fr.dyade.aaa.agent
Class MessageInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by fr.dyade.aaa.agent.MessageInputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
BufferedMessageInputStream, ByteArrayMessageInputStream

public abstract class MessageInputStream
extends java.io.InputStream

Class used to receive messages through a stream.

Be careful this InputStream is not synchronized.


Field Summary
protected  byte[] buf
          The internal buffer where data is stored.
protected  boolean compressedFlows
           
protected  int count
          The number of valid bytes in the buffer.
protected static org.objectweb.util.monolog.api.Logger logmon
          Default logger for MessageInputStream.
protected  int pos
          The current position in the buffer.
 
Method Summary
protected static org.objectweb.util.monolog.api.Logger getLogger()
          Returns default logger for MessageInputStream.
abstract  int read()
          Reads the next byte of data from the input stream.
 int read(byte[] b)
          Reads some number of bytes from the input stream and stores them into the buffer array b.
abstract  int read(byte[] b, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
protected abstract  void readFully(int length)
          Reads length bytes of data from the input stream.
protected abstract  void readHeader()
          Reads the protocol header from this output stream.
protected  int readInt()
          Reads an int directly from the buffer.
protected  fr.dyade.aaa.agent.Message readMessage()
          Reads the message from this input stream.
protected  void readMessageHeader(fr.dyade.aaa.agent.Message msg)
          Reads the message header data from the buffer.
protected  short readShort()
          Reads a short directly from the buffer.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected byte[] buf
The internal buffer where data is stored.


count

protected int count
The number of valid bytes in the buffer.

The index one greater than the index of the last valid byte in the buffer.

This value is always in the range 0 through buf.length; elements buf[0] through buf[count-1] contain valid byte data.


pos

protected int pos
The current position in the buffer. This is the index of the next character to be read from the buf array.

This value is always in the range 0 through count. If it is less than count, then buf[pos] is the next byte to be supplied as input; if it is equal to count, then the next read or skip operation will require more bytes to be read from the contained input stream.


compressedFlows

protected boolean compressedFlows

logmon

protected static org.objectweb.util.monolog.api.Logger logmon
Default logger for MessageInputStream.

Method Detail

getLogger

protected static org.objectweb.util.monolog.api.Logger getLogger()
Returns default logger for MessageInputStream.

Returns:
default logger for MessageInputStream.

read

public abstract int read()
                  throws java.io.IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Subclass must provide an implementation of this method.

Specified by:
read in class java.io.InputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

public final int read(byte[] b)
               throws java.io.IOException
Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

The read(b) method for class InputStream has the same effect as: read(b, 0, b.length)

Overrides:
read in class java.io.InputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
java.lang.NullPointerException - if b is null.

read

public abstract int read(byte[] b,
                         int off,
                         int len)
                  throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

Overrides:
read in class java.io.InputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
java.lang.NullPointerException - If b is null.
java.lang.IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off

readShort

protected final short readShort()
Reads a short directly from the buffer. Be careful, the buffer must contain enough data to read the short.

Returns:
the short.

readInt

protected final int readInt()
Reads an int directly from the buffer. Be careful, the buffer must contain enough data to read the int.

Returns:
the int.

readHeader

protected abstract void readHeader()
                            throws java.io.IOException
Reads the protocol header from this output stream. Be careful, the buffer must contain enough data to read the short. This method must be overloaded in subclass.

Throws:
java.io.IOException

readMessageHeader

protected final void readMessageHeader(fr.dyade.aaa.agent.Message msg)
                                throws java.io.IOException
Reads the message header data from the buffer.

Parameters:
msg - The message to complete.
Throws:
java.io.IOException

readMessage

protected final fr.dyade.aaa.agent.Message readMessage()
                                                throws java.lang.Exception
Reads the message from this input stream.

Returns:
the incoming message.
Throws:
java.lang.Exception

readFully

protected abstract void readFully(int length)
                           throws java.io.IOException
Reads length bytes of data from the input stream. This method returns when length bytes are available or if end of stream is reached.

Throws:
java.io.IOException


Copyright © 2011 ScalAgent D.T.. All Rights Reserved.