Class DataByteArrayInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataInput, java.lang.AutoCloseable

    public final class DataByteArrayInputStream
    extends java.io.InputStream
    implements java.io.DataInput
    Optimized ByteArrayInputStream that can be used more than once
    • Field Detail

      • buf

        private byte[] buf
      • pos

        private int pos
      • offset

        private int offset
      • length

        private int length
    • Constructor Detail

      • DataByteArrayInputStream

        public DataByteArrayInputStream​(byte[] buf)
        Creates a StoreByteArrayInputStream.
        Parameters:
        buf - the input buffer.
      • DataByteArrayInputStream

        public DataByteArrayInputStream​(Buffer buffer)
        Creates a StoreByteArrayInputStream.
        Parameters:
        buffer - the input buffer.
      • DataByteArrayInputStream

        public DataByteArrayInputStream()
        Creates WireByteArrayInputStream with a minmalist byte array
    • Method Detail

      • restart

        public void restart​(Buffer buffer)
        reset the StoreByteArrayInputStream to use an new Buffer
        Parameters:
        buffer -
      • restart

        public void restart​(int size)
        re-start the input stream - reusing the current buffer
        Parameters:
        size -
      • size

        public int size()
        Returns:
        the size
      • getRawData

        public byte[] getRawData()
        Returns:
        the underlying data array
      • readBuffer

        public Buffer readBuffer​(int len)
      • restart

        public void restart​(byte[] newBuff)
        reset the StoreByteArrayInputStream to use an new byte array
        Parameters:
        newBuff -
      • restart

        public void restart()
      • read

        public int read()
        Reads the next byte of data from this 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 read method cannot block.

        Specified by:
        read in class java.io.InputStream
        Returns:
        the next byte of data, or -1 if the end of the stream has been reached.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
        Reads up to len bytes of data into an array of bytes from this input stream.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        b - the buffer into which the data is read.
        off - the start offset of the data.
        len - the maximum number of bytes 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.
      • available

        public int available()
        Overrides:
        available in class java.io.InputStream
        Returns:
        the number of bytes that can be read from the input stream without blocking.
      • readFully

        public void readFully​(byte[] b)
        Specified by:
        readFully in interface java.io.DataInput
      • readFully

        public void readFully​(byte[] b,
                              int off,
                              int len)
        Specified by:
        readFully in interface java.io.DataInput
      • skip

        public int skip​(int n)
      • skipBytes

        public int skipBytes​(int n)
        Specified by:
        skipBytes in interface java.io.DataInput
      • readBoolean

        public boolean readBoolean()
        Specified by:
        readBoolean in interface java.io.DataInput
      • readByte

        public byte readByte()
        Specified by:
        readByte in interface java.io.DataInput
      • readUnsignedByte

        public int readUnsignedByte()
        Specified by:
        readUnsignedByte in interface java.io.DataInput
      • readShort

        public short readShort()
        Specified by:
        readShort in interface java.io.DataInput
      • readUnsignedShort

        public int readUnsignedShort()
        Specified by:
        readUnsignedShort in interface java.io.DataInput
      • readChar

        public char readChar()
        Specified by:
        readChar in interface java.io.DataInput
      • readInt

        public int readInt()
        Specified by:
        readInt in interface java.io.DataInput
      • readLong

        public long readLong()
        Specified by:
        readLong in interface java.io.DataInput
      • readFloat

        public float readFloat()
                        throws java.io.IOException
        Specified by:
        readFloat in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readDouble

        public double readDouble()
                          throws java.io.IOException
        Specified by:
        readDouble in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readLine

        public java.lang.String readLine()
        Specified by:
        readLine in interface java.io.DataInput
      • readUTF

        public java.lang.String readUTF()
                                 throws java.io.IOException
        Specified by:
        readUTF in interface java.io.DataInput
        Throws:
        java.io.IOException
      • getPos

        public int getPos()
      • setPos

        public void setPos​(int pos)
      • getLength

        public int getLength()
      • setLength

        public void setLength​(int length)
      • readVarInt

        public int readVarInt()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readVarLong

        public long readVarLong()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readVarSignedInt

        public int readVarSignedInt()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • readVarSignedLong

        public long readVarSignedLong()
                               throws java.io.IOException
        Throws:
        java.io.IOException