Class MessageInputStream

    • 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
    • Constructor Detail

      • MessageInputStream

        MessageInputStream()
        Creates a MessageInputStream.
    • Method Detail

      • read

        public abstract int read()
                          throws 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 InputStream
        Returns:
        the next byte of data, or -1 if the end of the stream is reached.
        Throws:
        IOException - if an I/O error occurs.
      • read

        public final int read​(byte[] b)
                       throws 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 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:
        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 - if b is null.
      • read

        public abstract int read​(byte[] b,
                                 int off,
                                 int len)
                          throws 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 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:
        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 - If b is null.
        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 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:
        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 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.
        Parameters:
        length - number of byte to read.
        Throws:
        IOException - an error occurs.