Package io.micronaut.core.io.buffer
Class DelegateByteBuffer<T>
java.lang.Object
io.micronaut.core.io.buffer.DelegateByteBuffer<T>
- Type Parameters:
T
- The native buffer type
- All Implemented Interfaces:
ByteBuffer<T>
Delegate class for
ByteBuffer
.- Since:
- 4.0.0
- Author:
- Jonas Konrad
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionExposes this buffer's readable bytes as an NIOByteBuffer
.asNioBuffer
(int index, int length) Exposes this buffer's sub-region as an NIOByteBuffer
.capacity
(int capacity) Adjusts the capacity of this buffer.byte
getByte
(int index) Get the byte at the specified index.int
indexOf
(byte b) Find the index of the first occurrence of the given byte.int
Returns the maximum allowed capacity of this buffer.byte
read()
Gets a byte at the currentreaderIndex
and increases thereaderIndex
by1
in this buffer.read
(byte[] destination) Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=dst.length
).read
(byte[] destination, int offset, int length) Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).int
Returns the number of readable bytes which is equal to(this.writerIndex - this.readerIndex)
.readCharSequence
(int length, Charset charset) Gets aCharSequence
with the given length at the currentreaderIndex
and increases thereaderIndex
by the given length.int
Returns thereaderIndex
of this buffer.readerIndex
(int readPosition) Sets thereaderIndex
of this buffer.slice
(int index, int length) Create a newByteBuffer
whose contents is a shared subsequence of this data buffer's content.byte[]
Create a copy of the underlying storage frombuf
into a byte array.Convert theByteBuffer
into an input stream.Convert theByteBuffer
into an output stream.To string.int
Returns the number of writable bytes which is equal to(this.capacity - this.writerIndex)
.write
(byte b) Sets the specified byte at the currentwriterIndex
and increases thewriterIndex
by1
in this buffer.write
(byte[] source) Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=src.length
).write
(byte[] source, int offset, int length) Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
).write
(ByteBuffer... buffers) Write the givenByteBuffer
instances to this buffer.write
(CharSequence source, Charset charset) Transfers the specified source CharSequence's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=src.length
).write
(ByteBuffer... buffers) Write the givenByteBuffer
instances to this buffer.int
Returns thewriterIndex
of this buffer.writerIndex
(int position) Sets thewriterIndex
of this buffer.
-
Constructor Details
-
DelegateByteBuffer
-
-
Method Details
-
asNativeBuffer
- Specified by:
asNativeBuffer
in interfaceByteBuffer<T>
- Returns:
- The native buffer type
-
readableBytes
public int readableBytes()Description copied from interface:ByteBuffer
Returns the number of readable bytes which is equal to(this.writerIndex - this.readerIndex)
.- Specified by:
readableBytes
in interfaceByteBuffer<T>
- Returns:
- bytes
-
writableBytes
public int writableBytes()Description copied from interface:ByteBuffer
Returns the number of writable bytes which is equal to(this.capacity - this.writerIndex)
.- Specified by:
writableBytes
in interfaceByteBuffer<T>
- Returns:
- The bytes
-
maxCapacity
public int maxCapacity()Description copied from interface:ByteBuffer
Returns the maximum allowed capacity of this buffer. If a user attempts to increase the capacity of this buffer beyond the maximum capacity usingByteBuffer.capacity(int)
orIllegalArgumentException
.- Specified by:
maxCapacity
in interfaceByteBuffer<T>
- Returns:
- The max capacity
-
capacity
Description copied from interface:ByteBuffer
Adjusts the capacity of this buffer. If thenewCapacity
is less than the current capacity, the content of this buffer is truncated. If thenewCapacity
is greater than the current capacity, the buffer is appended with unspecified data whose length is(newCapacity - currentCapacity)
.- Specified by:
capacity
in interfaceByteBuffer<T>
- Parameters:
capacity
- capacity- Returns:
- The bytebuffer
-
readerIndex
public int readerIndex()Description copied from interface:ByteBuffer
Returns thereaderIndex
of this buffer.- Specified by:
readerIndex
in interfaceByteBuffer<T>
- Returns:
- The index
-
readerIndex
Description copied from interface:ByteBuffer
Sets thereaderIndex
of this buffer.- Specified by:
readerIndex
in interfaceByteBuffer<T>
- Parameters:
readPosition
- readPosition- Returns:
- The buffer
-
writerIndex
public int writerIndex()Description copied from interface:ByteBuffer
Returns thewriterIndex
of this buffer.- Specified by:
writerIndex
in interfaceByteBuffer<T>
- Returns:
- The index
-
writerIndex
Description copied from interface:ByteBuffer
Sets thewriterIndex
of this buffer.- Specified by:
writerIndex
in interfaceByteBuffer<T>
- Parameters:
position
- The position- Returns:
- The index as buffer
-
read
public byte read()Description copied from interface:ByteBuffer
Gets a byte at the currentreaderIndex
and increases thereaderIndex
by1
in this buffer.- Specified by:
read
in interfaceByteBuffer<T>
- Returns:
- bytes
-
readCharSequence
Description copied from interface:ByteBuffer
Gets aCharSequence
with the given length at the currentreaderIndex
and increases thereaderIndex
by the given length.- Specified by:
readCharSequence
in interfaceByteBuffer<T>
- Parameters:
length
- the length to readcharset
- that should be used- Returns:
- the sequence
-
read
Description copied from interface:ByteBuffer
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=dst.length
).- Specified by:
read
in interfaceByteBuffer<T>
- Parameters:
destination
- destination- Returns:
- bytesBuffer
-
read
Description copied from interface:ByteBuffer
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).- Specified by:
read
in interfaceByteBuffer<T>
- Parameters:
destination
- The destination byte arrayoffset
- the first index of the destinationlength
- the number of bytes to transfer- Returns:
- bytesBuffer
-
write
Description copied from interface:ByteBuffer
Sets the specified byte at the currentwriterIndex
and increases thewriterIndex
by1
in this buffer. The 24 high-order bits of the specified value are ignored.- Specified by:
write
in interfaceByteBuffer<T>
- Parameters:
b
- The byte to write- Returns:
- bytesBuffer
-
write
Description copied from interface:ByteBuffer
Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=src.length
).- Specified by:
write
in interfaceByteBuffer<T>
- Parameters:
source
- The source bytes- Returns:
- bytesBuffer
-
write
Description copied from interface:ByteBuffer
Transfers the specified source CharSequence's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=src.length
).- Specified by:
write
in interfaceByteBuffer<T>
- Parameters:
source
- The char sequencecharset
- The charset- Returns:
- This buffer
-
write
Description copied from interface:ByteBuffer
Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
).- Specified by:
write
in interfaceByteBuffer<T>
- Parameters:
source
- The source byte arrayoffset
- the first index of the sourcelength
- the number of bytes to transfer- Returns:
- bytesBuffer
-
write
Description copied from interface:ByteBuffer
Write the givenByteBuffer
instances to this buffer.- Specified by:
write
in interfaceByteBuffer<T>
- Parameters:
buffers
- The buffers to write- Returns:
- this buffer
-
write
Description copied from interface:ByteBuffer
Write the givenByteBuffer
instances to this buffer.- Specified by:
write
in interfaceByteBuffer<T>
- Parameters:
buffers
- The buffers to write- Returns:
- this buffer
-
slice
Description copied from interface:ByteBuffer
Create a newByteBuffer
whose contents is a shared subsequence of this data buffer's content. Data between this byte 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.- Specified by:
slice
in interfaceByteBuffer<T>
- Parameters:
index
- the index at which to start the slicelength
- the length of the slice- Returns:
- the specified slice of this data buffer
-
asNioBuffer
Description copied from interface:ByteBuffer
Exposes this buffer's readable bytes as an NIOByteBuffer
. The returned buffer shares the content with this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method is identical tobuf.nioBuffer(buf.readerIndex(), buf.readableBytes())
. This method does not modifyreaderIndex
orwriterIndex
of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer, and it adjusted its capacity.- Specified by:
asNioBuffer
in interfaceByteBuffer<T>
- Returns:
- byteBuffer
-
asNioBuffer
Description copied from interface:ByteBuffer
Exposes this buffer's sub-region as an NIOByteBuffer
. The returned buffer shares the content with this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer, and it adjusted its capacity.- Specified by:
asNioBuffer
in interfaceByteBuffer<T>
- Parameters:
index
- The indexlength
- The length- Returns:
- byteBuffer
-
toInputStream
Description copied from interface:ByteBuffer
Convert theByteBuffer
into an input stream.- Specified by:
toInputStream
in interfaceByteBuffer<T>
- Returns:
- this buffer as an input stream
-
toOutputStream
Description copied from interface:ByteBuffer
Convert theByteBuffer
into an output stream.- Specified by:
toOutputStream
in interfaceByteBuffer<T>
- Returns:
- this buffer as an input stream
-
toByteArray
public byte[] toByteArray()Description copied from interface:ByteBuffer
Create a copy of the underlying storage frombuf
into a byte array. The copy will start atByteBuffer.readerIndex()
and copyByteBuffer.readableBytes()
bytes.- Specified by:
toByteArray
in interfaceByteBuffer<T>
- Returns:
- byte array
-
toString
Description copied from interface:ByteBuffer
To string.- Specified by:
toString
in interfaceByteBuffer<T>
- Parameters:
charset
- converted charset- Returns:
- string
-
indexOf
public int indexOf(byte b) Description copied from interface:ByteBuffer
Find the index of the first occurrence of the given byte.- Specified by:
indexOf
in interfaceByteBuffer<T>
- Parameters:
b
- The byte to find- Returns:
- The index of the byte
-
getByte
public byte getByte(int index) Description copied from interface:ByteBuffer
Get the byte at the specified index.- Specified by:
getByte
in interfaceByteBuffer<T>
- Parameters:
index
- The index- Returns:
- The byte
-