Class ByteBuffer

    • Constructor Detail

      • ByteBuffer

        public ByteBuffer()
        construct new java.nio.ByteBuffer-based ByteBuffer with DEFAULT_INITIAL_CAPACITY
      • ByteBuffer

        public ByteBuffer​(int nCapacity)
        construct new java.nio.ByteBuffer-based ByteBuffer with DEFAULT_INITIAL_CAPACITY
        Parameters:
        nCapacity - initial capacity
    • Method Detail

      • capacity

        public int capacity()
        Specified by:
        capacity in interface IoBufferHeader
        Returns:
        the capacity of this buffer
      • clear

        public void clear()
        Description copied from interface: IoBufferHeader
        Clears this buffer. The position is set to zero amd the limit is set to the capacity.

        Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:

         buf.clear(); // Prepare buffer for reading
         in.read(buf); // Read data
         

        This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.

        Specified by:
        clear in interface IoBufferHeader
      • elements

        public byte[] elements()
        Specified by:
        elements in interface IoBuffer
        Returns:
        underlying raw byte[] array buffer (if available)
      • flip

        public void flip()
        Description copied from interface: IoBufferHeader
        Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

        After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:

         buf.put(magic);    // Prepend header
         in.read(buf);      // Read data into rest of buffer
         buf.flip();        // Flip buffer
         out.write(buf);    // Write header + data to channel
        Specified by:
        flip in interface IoBufferHeader
      • forceCapacity

        public void forceCapacity​(int length,
                                  int preserve)
        Description copied from interface: IoBufferHeader
        Forces buffer to contain the given number of entries, preserving just a part of the array.
        Specified by:
        forceCapacity in interface IoBufferHeader
        Parameters:
        length - the new minimum length for this array.
        preserve - the number of elements of the old buffer that shall be preserved in case a new allocation is necessary.
      • getBoolean

        public boolean getBoolean()
        Specified by:
        getBoolean in interface IoBuffer
      • getBoolean

        public boolean getBoolean​(int position)
        Specified by:
        getBoolean in interface IoBuffer
      • getBooleanArray

        public boolean[] getBooleanArray​(boolean[] dst,
                                         int length)
        Specified by:
        getBooleanArray in interface IoBuffer
      • getByte

        public byte getByte()
        Specified by:
        getByte in interface IoBuffer
      • getByte

        public byte getByte​(int position)
        Specified by:
        getByte in interface IoBuffer
      • getByteArray

        public byte[] getByteArray​(byte[] dst,
                                   int length)
        Specified by:
        getByteArray in interface IoBuffer
      • getChar

        public char getChar()
        Specified by:
        getChar in interface IoBuffer
      • getChar

        public char getChar​(int position)
        Specified by:
        getChar in interface IoBuffer
      • getCharArray

        public char[] getCharArray​(char[] dst,
                                   int length)
        Specified by:
        getCharArray in interface IoBuffer
      • getDouble

        public double getDouble()
        Specified by:
        getDouble in interface IoBuffer
      • getDouble

        public double getDouble​(int position)
        Specified by:
        getDouble in interface IoBuffer
      • getDoubleArray

        public double[] getDoubleArray​(double[] dst,
                                       int length)
        Specified by:
        getDoubleArray in interface IoBuffer
      • getFloat

        public float getFloat()
        Specified by:
        getFloat in interface IoBuffer
      • getFloat

        public float getFloat​(int position)
        Specified by:
        getFloat in interface IoBuffer
      • getFloatArray

        public float[] getFloatArray​(float[] dst,
                                     int length)
        Specified by:
        getFloatArray in interface IoBuffer
      • getInt

        public int getInt()
        Specified by:
        getInt in interface IoBuffer
      • getInt

        public int getInt​(int position)
        Specified by:
        getInt in interface IoBuffer
      • getIntArray

        public int[] getIntArray​(int[] dst,
                                 int length)
        Specified by:
        getIntArray in interface IoBuffer
      • getLong

        public long getLong()
        Specified by:
        getLong in interface IoBuffer
      • getLong

        public long getLong​(int position)
        Specified by:
        getLong in interface IoBuffer
      • getLongArray

        public long[] getLongArray​(long[] dst,
                                   int length)
        Specified by:
        getLongArray in interface IoBuffer
      • getShort

        public short getShort()
        Specified by:
        getShort in interface IoBuffer
      • getShort

        public short getShort​(int position)
        Specified by:
        getShort in interface IoBuffer
      • getShortArray

        public short[] getShortArray​(short[] dst,
                                     int length)
        Specified by:
        getShortArray in interface IoBuffer
      • getString

        public java.lang.String getString()
        Specified by:
        getString in interface IoBuffer
      • getString

        public java.lang.String getString​(int position)
        Specified by:
        getString in interface IoBuffer
      • getStringArray

        public java.lang.String[] getStringArray​(java.lang.String[] dst,
                                                 int length)
        Specified by:
        getStringArray in interface IoBuffer
      • hasRemaining

        public boolean hasRemaining()
        Specified by:
        hasRemaining in interface IoBufferHeader
        Returns:
        true if, and only if, there is at least one element remaining in this buffer
      • isEnforceSimpleStringEncoding

        public boolean isEnforceSimpleStringEncoding()
        Specified by:
        isEnforceSimpleStringEncoding in interface IoBuffer
        Returns:
        true the ISO-8859-1 character encoding is being enforced for data fields (better performance), otherwise UTF-8 is being used (more generic encoding)
      • setEnforceSimpleStringEncoding

        public void setEnforceSimpleStringEncoding​(boolean state)
        Specified by:
        setEnforceSimpleStringEncoding in interface IoBuffer
        Parameters:
        state - true the ISO-8859-1 character encoding is being enforced for data fields (better performance), otherwise UTF-8 is being used (more generic encoding)
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in interface IoBufferHeader
        Returns:
        true if, and only if, this buffer is read-only
      • limit

        public int limit()
        Specified by:
        limit in interface IoBufferHeader
        Returns:
        the limit of this buffer
      • limit

        public void limit​(int newLimit)
        Description copied from interface: IoBufferHeader
        Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.
        Specified by:
        limit in interface IoBufferHeader
        Parameters:
        newLimit - the new limit value; must be non-negative and no larger than this buffer's capacity
      • lock

        public java.util.concurrent.locks.ReadWriteLock lock()
        Description copied from interface: IoBufferHeader
        For efficiency/performance reasons the buffer implementation is not required to safe-guard each put/get method independently. Thus the user-code should acquire the given lock around a set of put/get appropriately.
        Specified by:
        lock in interface IoBufferHeader
        Returns:
        the read-write lock
      • position

        public int position()
        Specified by:
        position in interface IoBufferHeader
        Returns:
        the position of this buffer
      • position

        public void position​(int newPosition)
        Description copied from interface: IoBufferHeader
        Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.
        Specified by:
        position in interface IoBufferHeader
        Parameters:
        newPosition - the new position value; must be non-negative and no larger than the current limit
      • putBoolean

        public void putBoolean​(boolean value)
        Specified by:
        putBoolean in interface IoBuffer
      • putBoolean

        public void putBoolean​(int position,
                               boolean value)
        Specified by:
        putBoolean in interface IoBuffer
      • putBooleanArray

        public void putBooleanArray​(boolean[] src,
                                    int n)
        Specified by:
        putBooleanArray in interface IoBuffer
      • putByte

        public void putByte​(byte b)
        Specified by:
        putByte in interface IoBuffer
      • putByte

        public void putByte​(int position,
                            byte value)
        Specified by:
        putByte in interface IoBuffer
      • putByteArray

        public void putByteArray​(byte[] src,
                                 int n)
        Specified by:
        putByteArray in interface IoBuffer
      • putChar

        public void putChar​(char value)
        Specified by:
        putChar in interface IoBuffer
      • putChar

        public void putChar​(int position,
                            char value)
        Specified by:
        putChar in interface IoBuffer
      • putCharArray

        public void putCharArray​(char[] src,
                                 int n)
        Specified by:
        putCharArray in interface IoBuffer
      • putDouble

        public void putDouble​(double value)
        Specified by:
        putDouble in interface IoBuffer
      • putDouble

        public void putDouble​(int position,
                              double value)
        Specified by:
        putDouble in interface IoBuffer
      • putDoubleArray

        public void putDoubleArray​(double[] src,
                                   int n)
        Specified by:
        putDoubleArray in interface IoBuffer
      • putFloat

        public void putFloat​(float value)
        Specified by:
        putFloat in interface IoBuffer
      • putFloat

        public void putFloat​(int position,
                             float value)
        Specified by:
        putFloat in interface IoBuffer
      • putFloatArray

        public void putFloatArray​(float[] src,
                                  int n)
        Specified by:
        putFloatArray in interface IoBuffer
      • putInt

        public void putInt​(int value)
        Specified by:
        putInt in interface IoBuffer
      • putInt

        public void putInt​(int position,
                           int value)
        Specified by:
        putInt in interface IoBuffer
      • putIntArray

        public void putIntArray​(int[] src,
                                int n)
        Specified by:
        putIntArray in interface IoBuffer
      • putLong

        public void putLong​(long value)
        Specified by:
        putLong in interface IoBuffer
      • putLong

        public void putLong​(int position,
                            long value)
        Specified by:
        putLong in interface IoBuffer
      • putLongArray

        public void putLongArray​(long[] src,
                                 int n)
        Specified by:
        putLongArray in interface IoBuffer
      • putShort

        public void putShort​(short value)
        Specified by:
        putShort in interface IoBuffer
      • putShort

        public void putShort​(int position,
                             short value)
        Specified by:
        putShort in interface IoBuffer
      • putShortArray

        public void putShortArray​(short[] src,
                                  int n)
        Specified by:
        putShortArray in interface IoBuffer
      • putString

        public void putString​(java.lang.String string)
        Specified by:
        putString in interface IoBuffer
      • putString

        public void putString​(int position,
                              java.lang.String value)
        Specified by:
        putString in interface IoBuffer
      • putStringArray

        public void putStringArray​(java.lang.String[] src,
                                   int n)
        Specified by:
        putStringArray in interface IoBuffer
      • putStringISO8859

        public void putStringISO8859​(java.lang.String string)
        Specified by:
        putStringISO8859 in interface IoBuffer
      • remaining

        public int remaining()
        Specified by:
        remaining in interface IoBufferHeader
        Returns:
        the number of elements remaining in this buffer
      • reset

        public void reset()
        Description copied from interface: IoBufferHeader
        resets the buffer read/write position to zero
        Specified by:
        reset in interface IoBufferHeader
      • trim

        public void trim()
        Description copied from interface: IoBufferHeader
        Trims the internal buffer array so that the capacity is equal to the size.
        Specified by:
        trim in interface IoBufferHeader
        See Also:
        ArrayList.trimToSize()
      • trim

        public void trim​(int requestedCapacity)
        Description copied from interface: IoBufferHeader
        Trims the internal buffer array if it is too large. If the current array length is smaller than or equal to n, this method does nothing. Otherwise, it trims the array length to the maximum between requestedCapacity and IoBufferHeader.capacity().

        This method is useful when reusing FastBuffers. Clearing a list leaves the array length untouched. If you are reusing a list many times, you can call this method with a typical size to avoid keeping around a very large array just because of a few large transient lists.

        Specified by:
        trim in interface IoBufferHeader
        Parameters:
        requestedCapacity - the threshold for the trimming.