Class RawDataBuffer

  • All Implemented Interfaces:
    DataInput, DataOutput

    public final class RawDataBuffer
    extends Object
    implements DataOutput, DataInput

    A RawDataBuffer is a dynamically growing byte array.

    It implements DataOutput and DataInput to write or read data plus additional null-safe versions of the methods.

    This class does not implement any synchronization nor bound checking for maximum performance.
    Note that the UTF read/write methods are not compatible with the JDK implementation because they were modified to take advantage of the RawDataBuffer layout.

    • Constructor Detail

      • RawDataBuffer

        public RawDataBuffer​(int initialCapacity)
        Constructor
        Parameters:
        initialCapacity - initial buffer capacity
      • RawDataBuffer

        public RawDataBuffer​(byte[] initialBuffer)
        Constructor
        Parameters:
        initialBuffer - the initial buffer to use internally
    • Method Detail

      • writeNullableUTF

        public void writeNullableUTF​(String str)
        Write a string or null value to the stream
      • ensureCapacity

        public final void ensureCapacity​(int targetCapacity)
        Ensure that the buffer internal capacity is at least targetCapacity
        Parameters:
        targetCapacity - the expected capacity
      • setSize

        public void setSize​(int size)
        Set the buffer size (buffer is enlarged as necessary and padded with zeroes)
        Parameters:
        size -
      • write

        public void write​(int b)
        Specified by:
        write in interface DataOutput
      • write

        public void write​(byte[] data)
        Specified by:
        write in interface DataOutput
      • write

        public void write​(byte[] data,
                          int offset,
                          int len)
        Specified by:
        write in interface DataOutput
      • writeByte

        public void writeByte​(int b)
        Specified by:
        writeByte in interface DataOutput
      • readByte

        public byte readByte​(int position)
        Read a byte value at an arbitrary position in the buffer
        Parameters:
        position - the target position
      • writeByte

        public void writeByte​(byte v,
                              int position)
        Write a byte value at an arbitrary position in the buffer
        Parameters:
        v - the byte value
        position - the target position
      • writeInt

        public void writeInt​(int v)
        Specified by:
        writeInt in interface DataOutput
      • writeInt

        public void writeInt​(int v,
                             int pos)
        Write a int value at an arbitrary position in the stream
        Parameters:
        v - the int value
        pos - the target position
      • writeLong

        public void writeLong​(long v)
        Specified by:
        writeLong in interface DataOutput
      • writeFloat

        public void writeFloat​(float v)
        Specified by:
        writeFloat in interface DataOutput
      • writeDouble

        public void writeDouble​(double v)
        Specified by:
        writeDouble in interface DataOutput
      • writeChar

        public void writeChar​(int v)
        Specified by:
        writeChar in interface DataOutput
      • writeNullableByteArray

        public void writeNullableByteArray​(byte[] value)
        Write a nullable byte array to the stream
      • writeByteArray

        public void writeByteArray​(byte[] value)
        Write a nullable byte array to the stream
      • writeGeneric

        public void writeGeneric​(Object value)
        Write a generic type to the stream
      • read

        public void read​(byte[] b)
      • read

        public void read​(byte[] b,
                         int off,
                         int len)
      • readBytes

        public byte[] readBytes​(int len)
      • readFully

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

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

        public int skipBytes​(int n)
        Specified by:
        skipBytes in interface DataInput
      • readNullableUTF

        public String readNullableUTF()
        Read a string or null value from the stream
      • readNullableByteArray

        public byte[] readNullableByteArray()
        Read a nullable byte array from the stream
      • readByteArray

        public byte[] readByteArray()
        Read a nullable byte array from the stream
      • readGeneric

        public Object readGeneric()
        Read a generic type from the stream
      • clear

        public void clear()
      • reset

        public void reset()
      • size

        public int size()
      • pos

        public int pos()
      • toByteArray

        public byte[] toByteArray()
      • toByteArray

        public byte[] toByteArray​(int offset,
                                  int len)
      • putTo

        public void putTo​(ByteBuffer byteBuffer,
                          int offset,
                          int len)
      • getFrom

        public void getFrom​(ByteBuffer byteBuffer,
                            int offset,
                            int len)
      • copy

        public RawDataBuffer copy()
        Create a copy of this buffer
        Returns:
        a copy of this buffer