Class DataInOut

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkSize​(int size)  
      void clear()
      Clears this output stream.
      void compact()
      Сдвигает непрочитанные данные (readPos..writePos) в начало буфера.
      byte[] getData()  
      int getReadPos()  
      int getSizeForRead()  
      int getWritePos()  
      int indexOf​(int limit, byte val)
      Returns the index within this input stream of the first occurrence of the specified byte, or -1 if no such byte exists.
      int read​(byte[] b, int offset, int len)
      Reads a byte array from this input stream and returns the number of bytes actually read.
      int readInt()
      Returns the next int value from this input stream, casting it to an int value in the range -2147483648 to 2147483647.
      long readLong()
      Returns the next long value from this input stream, casting it to a long value in the range -9223372036854775808 to 9223372036854775807.
      int readUByte()
      Returns the next byte of data from this input stream, casting it to an unsigned byte value in the range 0-255.
      int readUShort()
      Returns the next unsigned short value from this input stream, casting it to an int value in the range 0-65535.
      void setData​(byte[] data)  
      void setReadPos​(int readPos)  
      void setWritePos​(int writePos)  
      void skipAllBytes()
      Skips all bytes in this input stream.
      void skipBytes​(int n)
      Skips the specified number of bytes in this input stream.
      byte[] toArray()
      Returns a copy of this input stream as an array of bytes.
      byte[] toArrayCopy()  
      java.lang.String toString()  
      void trim()  
      void write​(byte @NotNull [] b)
      Writes a byte array to this output stream and returns the number of bytes actually written.
      int write​(byte @NotNull [] b, int off, int len)
      Writes a byte array to this output stream and returns the number of bytes actually written.
      void write​(DataIn data)
      Writes a data input stream to this output stream.
      void writeByte​(int v)
      Writes a byte value to this output stream.
      int writeTo​(java.io.OutputStream out)
      Returns the size of the data that can be read from this input stream, in bytes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • data

        public byte[] data
      • writePos

        public int writePos
      • readPos

        public int readPos
    • Constructor Detail

      • DataInOut

        public DataInOut​(byte[] data,
                         int len)
      • DataInOut

        public DataInOut()
      • DataInOut

        public DataInOut​(int initSize)
      • DataInOut

        public DataInOut​(byte[] data)
    • Method Detail

      • toArray

        public byte[] toArray()
        Description copied from interface: DataIn
        Returns a copy of this input stream as an array of bytes.
        Specified by:
        toArray in interface DataIn
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • write

        public void write​(DataIn data)
        Description copied from interface: DataOut
        Writes a data input stream to this output stream.
        Specified by:
        write in interface DataOut
        Parameters:
        data - The data input stream to write.
      • getData

        public byte[] getData()
      • setData

        public void setData​(byte[] data)
      • getWritePos

        public int getWritePos()
      • setWritePos

        public void setWritePos​(int writePos)
      • getReadPos

        public int getReadPos()
      • setReadPos

        public void setReadPos​(int readPos)
      • clear

        public void clear()
        Description copied from interface: DataOut
        Clears this output stream.
        Specified by:
        clear in interface DataOut
      • compact

        public void compact()
        Сдвигает непрочитанные данные (readPos..writePos) в начало буфера. После вызова readPos=0, writePos=размер хвоста. Если данных нет — эквивалентно clear().
      • readInt

        public int readInt()
        Description copied from interface: DataIn
        Returns the next int value from this input stream, casting it to an int value in the range -2147483648 to 2147483647.
        Specified by:
        readInt in interface DataIn
      • readLong

        public long readLong()
        Description copied from interface: DataIn
        Returns the next long value from this input stream, casting it to a long value in the range -9223372036854775808 to 9223372036854775807.
        Specified by:
        readLong in interface DataIn
      • readUShort

        public int readUShort()
        Description copied from interface: DataIn
        Returns the next unsigned short value from this input stream, casting it to an int value in the range 0-65535.
        Specified by:
        readUShort in interface DataIn
      • toArrayCopy

        public byte[] toArrayCopy()
      • writeTo

        public int writeTo​(java.io.OutputStream out)
                    throws java.io.IOException
        Description copied from interface: DataIn
        Returns the size of the data that can be read from this input stream, in bytes.
        Specified by:
        writeTo in interface DataIn
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int offset,
                        int len)
        Description copied from interface: DataIn
        Reads a byte array from this input stream and returns the number of bytes actually read.
        Specified by:
        read in interface DataIn
        Parameters:
        b - The byte array to read into.
        offset - The starting position in the array to write to.
        len - The maximum number of bytes to read.
        Returns:
        The number of bytes actually read.
      • trim

        public void trim()
      • skipAllBytes

        public void skipAllBytes()
        Description copied from interface: DataIn
        Skips all bytes in this input stream.
        Specified by:
        skipAllBytes in interface DataIn
      • indexOf

        public int indexOf​(int limit,
                           byte val)
        Description copied from interface: DataIn
        Returns the index within this input stream of the first occurrence of the specified byte, or -1 if no such byte exists.
        Specified by:
        indexOf in interface DataIn
      • skipBytes

        public void skipBytes​(int n)
        Description copied from interface: DataIn
        Skips the specified number of bytes in this input stream.
        Specified by:
        skipBytes in interface DataIn
        Parameters:
        n - The number of bytes to skip.
      • write

        public void write​(byte @NotNull [] b)
        Description copied from interface: DataOut
        Writes a byte array to this output stream and returns the number of bytes actually written.
        Specified by:
        write in interface DataOut
        Parameters:
        b - The byte array to write from.
      • write

        public int write​(byte @NotNull [] b,
                         int off,
                         int len)
        Description copied from interface: DataOut
        Writes a byte array to this output stream and returns the number of bytes actually written.
        Specified by:
        write in interface DataOut
        Parameters:
        b - The byte array to write from.
        off - The starting position in the array to read from.
        len - The maximum number of bytes to write.
      • readUByte

        public int readUByte()
        Description copied from interface: DataIn
        Returns the next byte of data from this input stream, casting it to an unsigned byte value in the range 0-255.
        Specified by:
        readUByte in interface DataIn
      • writeByte

        public void writeByte​(int v)
        Description copied from interface: DataOut
        Writes a byte value to this output stream.
        Specified by:
        writeByte in interface DataOut
        Parameters:
        v - The byte value to write.
      • checkSize

        public void checkSize​(int size)