public class DataBufferWrapper extends Object implements DataBuffer
DataBuffer interface
 that can be overridden to adapt the delegate.
 These methods default to calling through to the wrapped delegate object.
| Constructor and Description | 
|---|
| DataBufferWrapper(DataBuffer delegate)Create a new  DataBufferWrapperthat wraps the given buffer. | 
| Modifier and Type | Method and Description | 
|---|---|
| ByteBuffer | asByteBuffer()Expose this buffer's bytes as a  ByteBuffer. | 
| ByteBuffer | asByteBuffer(int index,
            int length)Expose a subsequence of this buffer's bytes as a  ByteBuffer. | 
| InputStream | asInputStream()Expose this buffer's data as an  InputStream. | 
| InputStream | asInputStream(boolean releaseOnClose)Expose this buffer's data as an  InputStream. | 
| OutputStream | asOutputStream()Expose this buffer's data as an  OutputStream. | 
| int | capacity()Return the number of bytes that this buffer can contain. | 
| DataBuffer | capacity(int capacity)Set the number of bytes that this buffer can contain. | 
| DataBuffer | dataBuffer()Return the wrapped delegate. | 
| DataBuffer | ensureCapacity(int capacity)Ensure that the current buffer has enough  DataBuffer.writableByteCount()to write the amount of data given as an argument. | 
| DataBufferFactory | factory()Return the  DataBufferFactorythat created this buffer. | 
| byte | getByte(int index)Read a single byte at the given index from this data buffer. | 
| int | indexOf(IntPredicate predicate,
       int fromIndex)Return the index of the first byte in this buffer that matches
 the given predicate. | 
| int | lastIndexOf(IntPredicate predicate,
           int fromIndex)Return the index of the last byte in this buffer that matches
 the given predicate. | 
| byte | read()Read a single byte from the current reading position from this data buffer. | 
| DataBuffer | read(byte[] destination)Read this buffer's data into the specified destination, starting at the current
 reading position of this buffer. | 
| DataBuffer | read(byte[] destination,
    int offset,
    int length)Read at most  lengthbytes of this buffer into the specified destination,
 starting at the current reading position of this buffer. | 
| int | readableByteCount()Return the number of bytes that can be read from this data buffer. | 
| int | readPosition()Return the position from which this buffer will read. | 
| DataBuffer | readPosition(int readPosition)Set the position from which this buffer will read. | 
| DataBuffer | retainedSlice(int index,
             int length)Create a new  DataBufferwhose contents is a shared, retained subsequence of this
 data buffer's content. | 
| DataBuffer | slice(int index,
     int length)Create a new  DataBufferwhose contents is a shared subsequence of this
 data buffer's content. | 
| String | toString(Charset charset)Return this buffer's data a String using the specified charset. | 
| String | toString(int index,
        int length,
        Charset charset)Return a part of this buffer's data as a String using the specified charset. | 
| int | writableByteCount()Return the number of bytes that can be written to this data buffer. | 
| DataBuffer | write(byte b)Write a single byte into this buffer at the current writing position. | 
| DataBuffer | write(byte[] source)Write the given source into this buffer, starting at the current writing position
 of this buffer. | 
| DataBuffer | write(byte[] source,
     int offset,
     int length)Write at most  lengthbytes of the given source into this buffer, starting
 at the current writing position of this buffer. | 
| DataBuffer | write(ByteBuffer... buffers)Write one or more  ByteBufferto this buffer, starting at the current
 writing position. | 
| DataBuffer | write(CharSequence charSequence,
     Charset charset)Write the given  CharSequenceusing the givenCharset,
 starting at the current writing position. | 
| DataBuffer | write(DataBuffer... buffers)Write one or more  DataBuffers to this buffer, starting at the current
 writing position. | 
| int | writePosition()Return the position to which this buffer will write. | 
| DataBuffer | writePosition(int writePosition)Set the position to which this buffer will write. | 
public DataBufferWrapper(DataBuffer delegate)
DataBufferWrapper that wraps the given buffer.delegate - the buffer to wrappublic DataBuffer dataBuffer()
public DataBufferFactory factory()
DataBufferDataBufferFactory that created this buffer.factory in interface DataBufferpublic int indexOf(IntPredicate predicate, int fromIndex)
DataBufferindexOf in interface DataBufferpredicate - the predicate to matchfromIndex - the index to start the search frompredicate;
 or -1 if none matchpublic int lastIndexOf(IntPredicate predicate, int fromIndex)
DataBufferlastIndexOf in interface DataBufferpredicate - the predicate to matchfromIndex - the index to start the search frompredicate;
 or -1 if none matchpublic int readableByteCount()
DataBufferreadableByteCount in interface DataBufferpublic int writableByteCount()
DataBufferwritableByteCount in interface DataBufferpublic int capacity()
DataBuffercapacity in interface DataBufferpublic DataBuffer capacity(int capacity)
DataBufferIf the new capacity is lower than the current capacity, the contents of this buffer will be truncated. If the new capacity is higher than the current capacity, it will be expanded.
capacity in interface DataBuffercapacity - the new capacitypublic DataBuffer ensureCapacity(int capacity)
DataBufferDataBuffer.writableByteCount()
 to write the amount of data given as an argument. If not, the missing
 capacity will be added to the buffer.ensureCapacity in interface DataBuffercapacity - the writable capacity to check forpublic int readPosition()
DataBufferreadPosition in interface DataBufferpublic DataBuffer readPosition(int readPosition)
DataBufferreadPosition in interface DataBufferreadPosition - the new read positionpublic int writePosition()
DataBufferwritePosition in interface DataBufferpublic DataBuffer writePosition(int writePosition)
DataBufferwritePosition in interface DataBufferwritePosition - the new write positionpublic byte getByte(int index)
DataBuffergetByte in interface DataBufferindex - the index at which the byte will be readpublic byte read()
DataBufferread in interface DataBufferpublic DataBuffer read(byte[] destination)
DataBufferread in interface DataBufferdestination - the array into which the bytes are to be writtenpublic DataBuffer read(byte[] destination, int offset, int length)
DataBufferlength bytes of this buffer into the specified destination,
 starting at the current reading position of this buffer.read in interface DataBufferdestination - the array into which the bytes are to be writtenoffset - the index within destination of the first byte to be writtenlength - the maximum number of bytes to be written in destinationpublic DataBuffer write(byte b)
DataBufferwrite in interface DataBufferb - the byte to be writtenpublic DataBuffer write(byte[] source)
DataBufferwrite in interface DataBuffersource - the bytes to be written into this bufferpublic DataBuffer write(byte[] source, int offset, int length)
DataBufferlength bytes of the given source into this buffer, starting
 at the current writing position of this buffer.write in interface DataBuffersource - the bytes to be written into this bufferoffset - the index within source to start writing fromlength - the maximum number of bytes to be written from sourcepublic DataBuffer write(DataBuffer... buffers)
DataBufferDataBuffers to this buffer, starting at the current
 writing position. It is the responsibility of the caller to
 release the given data buffers.write in interface DataBufferbuffers - the byte buffers to write into this bufferpublic DataBuffer write(ByteBuffer... buffers)
DataBufferByteBuffer to this buffer, starting at the current
 writing position.write in interface DataBufferbuffers - the byte buffers to write into this bufferpublic DataBuffer write(CharSequence charSequence, Charset charset)
DataBufferCharSequence using the given Charset,
 starting at the current writing position.write in interface DataBuffercharSequence - the char sequence to write into this buffercharset - the charset to encode the char sequence withpublic DataBuffer slice(int index, int length)
DataBufferDataBuffer whose contents is a shared subsequence of this
 data buffer's content.  Data between this data buffer and the returned buffer is
 shared; though changes in the returned buffer's position will not be reflected
 in the reading nor writing position of this data buffer.
 Note that this method will not call
 DataBufferUtils.retain(DataBuffer) on the resulting slice: the reference
 count will not be increased.
slice in interface DataBufferindex - the index at which to start the slicelength - the length of the slicepublic DataBuffer retainedSlice(int index, int length)
DataBufferDataBuffer whose contents is a shared, retained subsequence of this
 data buffer's content.  Data between this data buffer and the returned buffer is
 shared; though changes in the returned buffer's position will not be reflected
 in the reading nor writing position of this data buffer.
 Note that unlike DataBuffer.slice(int, int), this method
 will call DataBufferUtils.retain(DataBuffer) (or equivalent) on the
 resulting slice.
retainedSlice in interface DataBufferindex - the index at which to start the slicelength - the length of the slicepublic ByteBuffer asByteBuffer()
DataBufferByteBuffer. Data between this
 DataBuffer and the returned ByteBuffer is shared; though
 changes in the returned buffer's position
 will not be reflected in the reading nor writing position of this data buffer.asByteBuffer in interface DataBufferpublic ByteBuffer asByteBuffer(int index, int length)
DataBufferByteBuffer. Data between
 this DataBuffer and the returned ByteBuffer is shared; though
 changes in the returned buffer's position
 will not be reflected in the reading nor writing position of this data buffer.asByteBuffer in interface DataBufferindex - the index at which to start the byte bufferlength - the length of the returned byte bufferpublic InputStream asInputStream()
DataBufferInputStream. Both data and read position are
 shared between the returned stream and this data buffer. The underlying buffer will
 not be released
 when the input stream is closed.asInputStream in interface DataBufferDataBuffer.asInputStream(boolean)public InputStream asInputStream(boolean releaseOnClose)
DataBufferInputStream. Both data and read position are
 shared between the returned stream and this data buffer.asInputStream in interface DataBufferreleaseOnClose - whether the underlying buffer will be
 released when the input stream is
 closed.public OutputStream asOutputStream()
DataBufferOutputStream. Both data and write position are
 shared between the returned stream and this data buffer.asOutputStream in interface DataBufferpublic String toString(Charset charset)
DataBuffertoString(readPosition(), readableByteCount(), charset).toString in interface DataBuffercharset - the character set to usepublic String toString(int index, int length, Charset charset)
DataBuffertoString in interface DataBufferindex - the index at which to start the stringlength - the number of bytes to use for the stringcharset - the charset to use