Class ByteBufferProxy

  • All Implemented Interfaces:
    java.lang.Comparable<ByteBuffer>

    public class ByteBufferProxy
    extends ByteBuffer
    A ByteBuffer that wraps a buffer and proxies any operations to it.

    You can think this class like a FilterOutputStream. All operations are proxied by default so that you can extend this class and override existing operations selectively. You can introduce new operations, too.

    • Field Detail

      • buf

        protected ByteBuffer buf
        The buffer proxied by this proxy.
    • Constructor Detail

      • ByteBufferProxy

        protected ByteBufferProxy​(ByteBuffer buf)
        Create a new instance.
        Parameters:
        buf - the buffer to be proxied
    • Method Detail

      • acquire

        public void acquire()
        Description copied from class: ByteBuffer
        Increases the internal reference count of this buffer to defer automatic release. You have to invoke ByteBuffer.release() as many as you invoked this method to release this buffer.
        Specified by:
        acquire in class ByteBuffer
      • release

        public void release()
        Description copied from class: ByteBuffer
        Releases the specified buffer to buffer pool.
        Specified by:
        release in class ByteBuffer
      • isDirect

        public boolean isDirect()
        Specified by:
        isDirect in class ByteBuffer
        See Also:
        ByteBuffer.isDirect()
      • buf

        public java.nio.ByteBuffer buf()
        Description copied from class: ByteBuffer
        Returns the underlying NIO buffer instance.
        Specified by:
        buf in class ByteBuffer
      • capacity

        public int capacity()
        Specified by:
        capacity in class ByteBuffer
        See Also:
        Buffer.capacity()
      • position

        public int position()
        Specified by:
        position in class ByteBuffer
        See Also:
        Buffer.position()
      • limit

        public int limit()
        Specified by:
        limit in class ByteBuffer
        See Also:
        Buffer.limit()
      • sweep

        public ByteBuffer sweep()
        Description copied from class: ByteBuffer
        Clears this buffer and fills its content with NUL. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
        Overrides:
        sweep in class ByteBuffer
      • sweep

        public ByteBuffer sweep​(byte value)
        Description copied from class: ByteBuffer
        Clears this buffer and fills its content with value. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
        Overrides:
        sweep in class ByteBuffer
      • remaining

        public int remaining()
        Overrides:
        remaining in class ByteBuffer
        See Also:
        Buffer.remaining()
      • hasRemaining

        public boolean hasRemaining()
        Overrides:
        hasRemaining in class ByteBuffer
        See Also:
        Buffer.hasRemaining()
      • get

        public byte get()
        Specified by:
        get in class ByteBuffer
        See Also:
        ByteBuffer.get()
      • getUnsigned

        public short getUnsigned()
        Description copied from class: ByteBuffer
        Reads one unsigned byte as a short integer.
        Overrides:
        getUnsigned in class ByteBuffer
      • get

        public byte get​(int index)
        Specified by:
        get in class ByteBuffer
        See Also:
        ByteBuffer.get(int)
      • getUnsigned

        public short getUnsigned​(int index)
        Description copied from class: ByteBuffer
        Reads one byte as an unsigned short integer.
        Overrides:
        getUnsigned in class ByteBuffer
      • put

        public ByteBuffer put​(int index,
                              byte b)
        Specified by:
        put in class ByteBuffer
        See Also:
        ByteBuffer.put(int, byte)
      • get

        public ByteBuffer get​(byte[] dst,
                              int offset,
                              int length)
        Specified by:
        get in class ByteBuffer
        See Also:
        ByteBuffer.get(byte[], int, int)
      • get

        public ByteBuffer get​(byte[] dst)
        Overrides:
        get in class ByteBuffer
        See Also:
        ByteBuffer.get(byte[])
      • put

        public ByteBuffer put​(java.nio.ByteBuffer src)
        Description copied from class: ByteBuffer
        Writes the content of the specified src into this buffer.
        Specified by:
        put in class ByteBuffer
      • put

        public ByteBuffer put​(byte[] src,
                              int offset,
                              int length)
        Specified by:
        put in class ByteBuffer
        See Also:
        ByteBuffer.put(byte[], int, int)
      • put

        public ByteBuffer put​(byte[] src)
        Overrides:
        put in class ByteBuffer
        See Also:
        ByteBuffer.put(byte[])
      • equals

        public boolean equals​(java.lang.Object ob)
        Overrides:
        equals in class ByteBuffer
      • order

        public java.nio.ByteOrder order()
        Specified by:
        order in class ByteBuffer
        See Also:
        ByteBuffer.order()
      • order

        public ByteBuffer order​(java.nio.ByteOrder bo)
        Specified by:
        order in class ByteBuffer
        See Also:
        ByteBuffer.order(ByteOrder)
      • getChar

        public char getChar()
        Specified by:
        getChar in class ByteBuffer
        See Also:
        ByteBuffer.getChar()
      • getChar

        public char getChar​(int index)
        Specified by:
        getChar in class ByteBuffer
        See Also:
        ByteBuffer.getChar(int)
      • putChar

        public ByteBuffer putChar​(int index,
                                  char value)
        Specified by:
        putChar in class ByteBuffer
        See Also:
        ByteBuffer.putChar(int, char)
      • asCharBuffer

        public java.nio.CharBuffer asCharBuffer()
        Specified by:
        asCharBuffer in class ByteBuffer
        See Also:
        ByteBuffer.asCharBuffer()
      • getShort

        public short getShort()
        Specified by:
        getShort in class ByteBuffer
        See Also:
        ByteBuffer.getShort()
      • getShort

        public short getShort​(int index)
        Specified by:
        getShort in class ByteBuffer
        See Also:
        ByteBuffer.getShort()
      • getUnsignedShort

        public int getUnsignedShort​(int index)
        Description copied from class: ByteBuffer
        Reads two bytes unsigned integer.
        Overrides:
        getUnsignedShort in class ByteBuffer
      • putShort

        public ByteBuffer putShort​(int index,
                                   short value)
        Specified by:
        putShort in class ByteBuffer
        See Also:
        ByteBuffer.putShort(int, short)
      • asShortBuffer

        public java.nio.ShortBuffer asShortBuffer()
        Specified by:
        asShortBuffer in class ByteBuffer
        See Also:
        ByteBuffer.asShortBuffer()
      • getInt

        public int getInt()
        Specified by:
        getInt in class ByteBuffer
        See Also:
        ByteBuffer.getInt()
      • getUnsignedInt

        public long getUnsignedInt()
        Description copied from class: ByteBuffer
        Reads four bytes unsigned integer.
        Overrides:
        getUnsignedInt in class ByteBuffer
      • getInt

        public int getInt​(int index)
        Specified by:
        getInt in class ByteBuffer
        See Also:
        ByteBuffer.getInt(int)
      • getUnsignedInt

        public long getUnsignedInt​(int index)
        Description copied from class: ByteBuffer
        Reads four bytes unsigned integer.
        Overrides:
        getUnsignedInt in class ByteBuffer
      • putInt

        public ByteBuffer putInt​(int index,
                                 int value)
        Specified by:
        putInt in class ByteBuffer
        See Also:
        ByteBuffer.putInt(int, int)
      • asIntBuffer

        public java.nio.IntBuffer asIntBuffer()
        Specified by:
        asIntBuffer in class ByteBuffer
        See Also:
        ByteBuffer.asIntBuffer()
      • getLong

        public long getLong()
        Specified by:
        getLong in class ByteBuffer
        See Also:
        ByteBuffer.getLong()
      • putLong

        public ByteBuffer putLong​(long value)
        Specified by:
        putLong in class ByteBuffer
        See Also:
        ByteBuffer.putLong(int, long)
      • getLong

        public long getLong​(int index)
        Specified by:
        getLong in class ByteBuffer
        See Also:
        ByteBuffer.getLong(int)
      • putLong

        public ByteBuffer putLong​(int index,
                                  long value)
        Specified by:
        putLong in class ByteBuffer
        See Also:
        ByteBuffer.putLong(int, long)
      • asLongBuffer

        public java.nio.LongBuffer asLongBuffer()
        Specified by:
        asLongBuffer in class ByteBuffer
        See Also:
        ByteBuffer.asLongBuffer()
      • getFloat

        public float getFloat()
        Specified by:
        getFloat in class ByteBuffer
        See Also:
        ByteBuffer.getFloat()
      • getFloat

        public float getFloat​(int index)
        Specified by:
        getFloat in class ByteBuffer
        See Also:
        ByteBuffer.getFloat(int)
      • putFloat

        public ByteBuffer putFloat​(int index,
                                   float value)
        Specified by:
        putFloat in class ByteBuffer
        See Also:
        ByteBuffer.putFloat(int, float)
      • asFloatBuffer

        public java.nio.FloatBuffer asFloatBuffer()
        Specified by:
        asFloatBuffer in class ByteBuffer
        See Also:
        ByteBuffer.asFloatBuffer()
      • getDouble

        public double getDouble()
        Specified by:
        getDouble in class ByteBuffer
        See Also:
        ByteBuffer.getDouble()
      • getDouble

        public double getDouble​(int index)
        Specified by:
        getDouble in class ByteBuffer
        See Also:
        ByteBuffer.getDouble(int)
      • putDouble

        public ByteBuffer putDouble​(int index,
                                    double value)
        Specified by:
        putDouble in class ByteBuffer
        See Also:
        ByteBuffer.putDouble(int, double)
      • asDoubleBuffer

        public java.nio.DoubleBuffer asDoubleBuffer()
        Specified by:
        asDoubleBuffer in class ByteBuffer
        See Also:
        ByteBuffer.asDoubleBuffer()
      • getHexDump

        public java.lang.String getHexDump()
        Description copied from class: ByteBuffer
        Returns hexdump of this buffer.
        Overrides:
        getHexDump in class ByteBuffer
      • getString

        public java.lang.String getString​(int fieldSize,
                                          java.nio.charset.CharsetDecoder decoder)
                                   throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Reads a NUL-terminated string from this buffer using the specified decoder and returns it.
        Overrides:
        getString in class ByteBuffer
        Parameters:
        fieldSize - the maximum number of bytes to read
        Throws:
        java.nio.charset.CharacterCodingException
      • getString

        public java.lang.String getString​(java.nio.charset.CharsetDecoder decoder)
                                   throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Reads a NUL-terminated string from this buffer using the specified decoder and returns it. This method reads until the limit of this buffer if no NUL is found.
        Overrides:
        getString in class ByteBuffer
        Throws:
        java.nio.charset.CharacterCodingException
      • getPrefixedString

        public java.lang.String getPrefixedString​(java.nio.charset.CharsetDecoder decoder)
                                           throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Reads a string which has a 16-bit length field before the actual encoded string, using the specified decoder and returns it. This method is a shortcut for getPrefixedString(2, decoder).
        Overrides:
        getPrefixedString in class ByteBuffer
        Throws:
        java.nio.charset.CharacterCodingException
      • getPrefixedString

        public java.lang.String getPrefixedString​(int prefixLength,
                                                  java.nio.charset.CharsetDecoder decoder)
                                           throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Reads a string which has a length field before the actual encoded string, using the specified decoder and returns it.
        Overrides:
        getPrefixedString in class ByteBuffer
        Parameters:
        prefixLength - the length of the length field (1, 2, or 4)
        Throws:
        java.nio.charset.CharacterCodingException
      • putString

        public ByteBuffer putString​(java.lang.CharSequence in,
                                    int fieldSize,
                                    java.nio.charset.CharsetEncoder encoder)
                             throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Writes the content of in into this buffer as a NUL-terminated string using the specified encoder.

        If the charset name of the encoder is UTF-16, you cannot specify odd fieldSize, and this method will append two NULs as a terminator.

        Please note that this method doesn't terminate with NUL if the input string is longer than fieldSize.

        Overrides:
        putString in class ByteBuffer
        fieldSize - the maximum number of bytes to write
        Throws:
        java.nio.charset.CharacterCodingException
      • putString

        public ByteBuffer putString​(java.lang.CharSequence in,
                                    java.nio.charset.CharsetEncoder encoder)
                             throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Writes the content of in into this buffer using the specified encoder. This method doesn't terminate string with NUL. You have to do it by yourself.
        Overrides:
        putString in class ByteBuffer
        Throws:
        java.nio.charset.CharacterCodingException
      • putPrefixedString

        public ByteBuffer putPrefixedString​(java.lang.CharSequence in,
                                            java.nio.charset.CharsetEncoder encoder)
                                     throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Writes the content of in into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specified encoder. This method is a shortcut for putPrefixedString(in, 2, 0, encoder).
        Overrides:
        putPrefixedString in class ByteBuffer
        Throws:
        java.nio.charset.CharacterCodingException
      • putPrefixedString

        public ByteBuffer putPrefixedString​(java.lang.CharSequence in,
                                            int prefixLength,
                                            java.nio.charset.CharsetEncoder encoder)
                                     throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Writes the content of in into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specified encoder. This method is a shortcut for putPrefixedString(in, prefixLength, 0, encoder).
        Overrides:
        putPrefixedString in class ByteBuffer
        prefixLength - the length of the length field (1, 2, or 4)
        Throws:
        java.nio.charset.CharacterCodingException
      • putPrefixedString

        public ByteBuffer putPrefixedString​(java.lang.CharSequence in,
                                            int prefixLength,
                                            int padding,
                                            java.nio.charset.CharsetEncoder encoder)
                                     throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Writes the content of in into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specified encoder. This method is a shortcut for putPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder).
        Overrides:
        putPrefixedString in class ByteBuffer
        prefixLength - the length of the length field (1, 2, or 4)
        padding - the number of padded NULs (1 (or 0), 2, or 4)
        Throws:
        java.nio.charset.CharacterCodingException
      • putPrefixedString

        public ByteBuffer putPrefixedString​(java.lang.CharSequence in,
                                            int prefixLength,
                                            int padding,
                                            byte padValue,
                                            java.nio.charset.CharsetEncoder encoder)
                                     throws java.nio.charset.CharacterCodingException
        Description copied from class: ByteBuffer
        Writes the content of in into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specified encoder.
        Overrides:
        putPrefixedString in class ByteBuffer
        prefixLength - the length of the length field (1, 2, or 4)
        padding - the number of padded bytes (1 (or 0), 2, or 4)
        padValue - the value of padded bytes
        Throws:
        java.nio.charset.CharacterCodingException
      • skip

        public ByteBuffer skip​(int size)
        Description copied from class: ByteBuffer
        Forwards the position of this buffer as the specified size bytes.
        Overrides:
        skip in class ByteBuffer
      • fill

        public ByteBuffer fill​(byte value,
                               int size)
        Description copied from class: ByteBuffer
        Fills this buffer with the specified value. This method moves buffer position forward.
        Overrides:
        fill in class ByteBuffer
      • fillAndReset

        public ByteBuffer fillAndReset​(byte value,
                                       int size)
        Description copied from class: ByteBuffer
        Fills this buffer with the specified value. This method does not change buffer position.
        Overrides:
        fillAndReset in class ByteBuffer
      • fill

        public ByteBuffer fill​(int size)
        Description copied from class: ByteBuffer
        Fills this buffer with NUL (0x00). This method moves buffer position forward.
        Overrides:
        fill in class ByteBuffer
      • fillAndReset

        public ByteBuffer fillAndReset​(int size)
        Description copied from class: ByteBuffer
        Fills this buffer with NUL (0x00). This method does not change buffer position.
        Overrides:
        fillAndReset in class ByteBuffer
      • isAutoExpand

        public boolean isAutoExpand()
        Description copied from class: ByteBuffer
        Returns true if and only if autoExpand is turned on.
        Specified by:
        isAutoExpand in class ByteBuffer
      • expand

        public ByteBuffer expand​(int pos,
                                 int expectedRemaining)
        Description copied from class: ByteBuffer
        Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the specified pos. This method works even if you didn't set autoExpand to true.
        Specified by:
        expand in class ByteBuffer
      • expand

        public ByteBuffer expand​(int expectedRemaining)
        Description copied from class: ByteBuffer
        Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the current position. This method works even if you didn't set autoExpand to true.
        Overrides:
        expand in class ByteBuffer
      • getObject

        public java.lang.Object getObject()
                                   throws java.lang.ClassNotFoundException
        Description copied from class: ByteBuffer
        Reads a Java object from the buffer using the context ClassLoader of the current thread.
        Overrides:
        getObject in class ByteBuffer
        Throws:
        java.lang.ClassNotFoundException
      • getObject

        public java.lang.Object getObject​(java.lang.ClassLoader classLoader)
                                   throws java.lang.ClassNotFoundException
        Description copied from class: ByteBuffer
        Reads a Java object from the buffer using the specified classLoader.
        Overrides:
        getObject in class ByteBuffer
        Throws:
        java.lang.ClassNotFoundException
      • putObject

        public ByteBuffer putObject​(java.lang.Object o)
        Description copied from class: ByteBuffer
        Writes the specified Java object to the buffer.
        Overrides:
        putObject in class ByteBuffer
      • asInputStream

        public java.io.InputStream asInputStream()
        Description copied from class: ByteBuffer
        Returns an InputStream that reads the data from this buffer. InputStream.read() returns -1 if the buffer position reaches to the limit.
        Overrides:
        asInputStream in class ByteBuffer
      • asOutputStream

        public java.io.OutputStream asOutputStream()
        Description copied from class: ByteBuffer
        Returns an OutputStream that appends the data into this buffer. Please note that the OutputStream.write(int) will throw a BufferOverflowException instead of an IOException in case of buffer overflow. Please set autoExpand property by calling ByteBuffer.setAutoExpand(boolean) to prevent the unexpected runtime exception.
        Overrides:
        asOutputStream in class ByteBuffer
      • array

        public byte[] array()
        Specified by:
        array in class ByteBuffer
        See Also:
        ByteBuffer.array()
      • arrayOffset

        public int arrayOffset()
        Specified by:
        arrayOffset in class ByteBuffer
        See Also:
        ByteBuffer.arrayOffset()
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in class ByteBuffer
        See Also:
        Buffer.isReadOnly()
      • markValue

        public int markValue()
        Description copied from class: ByteBuffer
        Returns the position of the current mark. This method returns -1 if no mark is set.
        Specified by:
        markValue in class ByteBuffer