Class MessageInputStream
- java.lang.Object
-
- java.io.InputStream
-
- fr.dyade.aaa.agent.MessageInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
BufferedMessageInputStream,ByteArrayMessageInputStream
public abstract class MessageInputStream extends InputStream
Class used to receive messages through a stream.Be careful this InputStream is not synchronized.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufThe internal buffer where data is stored.protected booleancompressedFlowsprotected intcountThe number of valid bytes in the buffer.protected intposThe current position in the buffer.
-
Constructor Summary
Constructors Constructor Description MessageInputStream()Creates aMessageInputStream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intread()Reads the next byte of data from the input stream.intread(byte[] b)Reads some number of bytes from the input stream and stores them into the buffer arrayb.abstract intread(byte[] b, int off, int len)Reads up tolenbytes of data from the input stream into an array of bytes.protected abstract voidreadFully(int length)Reads length bytes of data from the input stream.protected abstract voidreadHeader()Reads the protocol header from this output stream.protected intreadInt()Reads an int directly from the buffer.protected MessagereadMessage()Reads the message from this input stream.protected voidreadMessageHeader(Message msg)Reads the message header data from the buffer.protected shortreadShort()Reads a short directly from the buffer.-
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
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 thebufarray.This value is always in the range
0throughcount. If it is less thancount, thenbuf[pos]is the next byte to be supplied as input; if it is equal tocount, then the nextreadorskipoperation will require more bytes to be read from the contained input stream.
-
compressedFlows
protected boolean compressedFlows
-
-
Method Detail
-
read
public abstract int read() throws IOExceptionReads the next byte of data from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is 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:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.
-
read
public final int read(byte[] b) throws IOExceptionReads some number of bytes from the input stream and stores them into the buffer arrayb. 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 classInputStreamhas the same effect as:read(b, 0, b.length)- Overrides:
readin classInputStream- Parameters:
b- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1is there is no more data because the end of the stream has been reached. - Throws:
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.NullPointerException- ifbisnull.
-
read
public abstract int read(byte[] b, int off, int len) throws IOExceptionReads up tolenbytes of data from the input stream into an array of bytes. An attempt is made to read as many aslenbytes, 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:
readin classInputStream- Parameters:
b- the buffer into which the data is read.off- the start offset in arraybat which the data is written.len- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or
-1if there is no more data because the end of the stream has been reached. - Throws:
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.NullPointerException- Ifbisnull.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanb.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 IOExceptionReads 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:
IOException- an error occurs.
-
readMessageHeader
protected final void readMessageHeader(Message msg) throws IOException
Reads the message header data from the buffer.- Parameters:
msg- The message to complete.- Throws:
IOException- an error occurs.
-
readMessage
protected final Message readMessage() throws Exception
Reads the message from this input stream.- Returns:
- the incoming message.
- Throws:
Exception- an error occurs.
-
readFully
protected abstract void readFully(int length) throws IOExceptionReads length bytes of data from the input stream. This method returns when length bytes are available or if end of stream is reached.- Parameters:
length- number of byte to read.- Throws:
IOException- an error occurs.
-
-