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
Constructors -
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.bytegetByte(int index) Get the byte at the specified index.intindexOf(byte b) Find the index of the first occurrence of the given byte.intReturns the maximum allowed capacity of this buffer.byteread()Gets a byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.read(byte[] destination) Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby 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 currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).intReturns the number of readable bytes which is equal to(this.writerIndex - this.readerIndex).readCharSequence(int length, Charset charset) Gets aCharSequencewith the given length at the currentreaderIndexand increases thereaderIndexby the given length.intReturns thereaderIndexof this buffer.readerIndex(int readPosition) Sets thereaderIndexof this buffer.slice(int index, int length) Create a newByteBufferwhose contents is a shared subsequence of this data buffer's content.byte[]Create a copy of the underlying storage frombufinto a byte array.Convert theByteBufferinto an input stream.Convert theByteBufferinto an output stream.To string.intReturns the number of writable bytes which is equal to(this.capacity - this.writerIndex).write(byte b) Sets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer.write(byte[] source) Transfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby 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 currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).write(ByteBuffer... buffers) Write the givenByteBufferinstances to this buffer.write(CharSequence source, Charset charset) Transfers the specified source CharSequence's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=src.length).write(ByteBuffer... buffers) Write the givenByteBufferinstances to this buffer.intReturns thewriterIndexof this buffer.writerIndex(int position) Sets thewriterIndexof this buffer.
-
Constructor Details
-
DelegateByteBuffer
-
-
Method Details
-
asNativeBuffer
- Specified by:
asNativeBufferin interfaceByteBuffer<T>- Returns:
- The native buffer type
-
readableBytes
public int readableBytes()Description copied from interface:ByteBufferReturns the number of readable bytes which is equal to(this.writerIndex - this.readerIndex).- Specified by:
readableBytesin interfaceByteBuffer<T>- Returns:
- bytes
-
writableBytes
public int writableBytes()Description copied from interface:ByteBufferReturns the number of writable bytes which is equal to(this.capacity - this.writerIndex).- Specified by:
writableBytesin interfaceByteBuffer<T>- Returns:
- The bytes
-
maxCapacity
public int maxCapacity()Description copied from interface:ByteBufferReturns 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:
maxCapacityin interfaceByteBuffer<T>- Returns:
- The max capacity
-
capacity
Description copied from interface:ByteBufferAdjusts the capacity of this buffer. If thenewCapacityis less than the current capacity, the content of this buffer is truncated. If thenewCapacityis greater than the current capacity, the buffer is appended with unspecified data whose length is(newCapacity - currentCapacity).- Specified by:
capacityin interfaceByteBuffer<T>- Parameters:
capacity- capacity- Returns:
- The bytebuffer
-
readerIndex
public int readerIndex()Description copied from interface:ByteBufferReturns thereaderIndexof this buffer.- Specified by:
readerIndexin interfaceByteBuffer<T>- Returns:
- The index
-
readerIndex
Description copied from interface:ByteBufferSets thereaderIndexof this buffer.- Specified by:
readerIndexin interfaceByteBuffer<T>- Parameters:
readPosition- readPosition- Returns:
- The buffer
-
writerIndex
public int writerIndex()Description copied from interface:ByteBufferReturns thewriterIndexof this buffer.- Specified by:
writerIndexin interfaceByteBuffer<T>- Returns:
- The index
-
writerIndex
Description copied from interface:ByteBufferSets thewriterIndexof this buffer.- Specified by:
writerIndexin interfaceByteBuffer<T>- Parameters:
position- The position- Returns:
- The index as buffer
-
read
public byte read()Description copied from interface:ByteBufferGets a byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.- Specified by:
readin interfaceByteBuffer<T>- Returns:
- bytes
-
readCharSequence
Description copied from interface:ByteBufferGets aCharSequencewith the given length at the currentreaderIndexand increases thereaderIndexby the given length.- Specified by:
readCharSequencein interfaceByteBuffer<T>- Parameters:
length- the length to readcharset- that should be used- Returns:
- the sequence
-
read
Description copied from interface:ByteBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=dst.length).- Specified by:
readin interfaceByteBuffer<T>- Parameters:
destination- destination- Returns:
- bytesBuffer
-
read
Description copied from interface:ByteBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).- Specified by:
readin 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:ByteBufferSets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer. The 24 high-order bits of the specified value are ignored.- Specified by:
writein interfaceByteBuffer<T>- Parameters:
b- The byte to write- Returns:
- bytesBuffer
-
write
Description copied from interface:ByteBufferTransfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=src.length).- Specified by:
writein interfaceByteBuffer<T>- Parameters:
source- The source bytes- Returns:
- bytesBuffer
-
write
Description copied from interface:ByteBufferTransfers the specified source CharSequence's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=src.length).- Specified by:
writein interfaceByteBuffer<T>- Parameters:
source- The char sequencecharset- The charset- Returns:
- This buffer
-
write
Description copied from interface:ByteBufferTransfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).- Specified by:
writein 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:ByteBufferWrite the givenByteBufferinstances to this buffer.- Specified by:
writein interfaceByteBuffer<T>- Parameters:
buffers- The buffers to write- Returns:
- this buffer
-
write
Description copied from interface:ByteBufferWrite the givenByteBufferinstances to this buffer.- Specified by:
writein interfaceByteBuffer<T>- Parameters:
buffers- The buffers to write- Returns:
- this buffer
-
slice
Description copied from interface:ByteBufferCreate a newByteBufferwhose 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:
slicein 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:ByteBufferExposes 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 modifyreaderIndexorwriterIndexof 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:
asNioBufferin interfaceByteBuffer<T>- Returns:
- byteBuffer
-
asNioBuffer
Description copied from interface:ByteBufferExposes 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 modifyreaderIndexorwriterIndexof 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:
asNioBufferin interfaceByteBuffer<T>- Parameters:
index- The indexlength- The length- Returns:
- byteBuffer
-
toInputStream
Description copied from interface:ByteBufferConvert theByteBufferinto an input stream.- Specified by:
toInputStreamin interfaceByteBuffer<T>- Returns:
- this buffer as an input stream
-
toOutputStream
Description copied from interface:ByteBufferConvert theByteBufferinto an output stream.- Specified by:
toOutputStreamin interfaceByteBuffer<T>- Returns:
- this buffer as an input stream
-
toByteArray
public byte[] toByteArray()Description copied from interface:ByteBufferCreate a copy of the underlying storage frombufinto a byte array. The copy will start atByteBuffer.readerIndex()and copyByteBuffer.readableBytes()bytes.- Specified by:
toByteArrayin interfaceByteBuffer<T>- Returns:
- byte array
-
toString
Description copied from interface:ByteBufferTo string.- Specified by:
toStringin interfaceByteBuffer<T>- Parameters:
charset- converted charset- Returns:
- string
-
indexOf
public int indexOf(byte b) Description copied from interface:ByteBufferFind the index of the first occurrence of the given byte.- Specified by:
indexOfin interfaceByteBuffer<T>- Parameters:
b- The byte to find- Returns:
- The index of the byte
-
getByte
public byte getByte(int index) Description copied from interface:ByteBufferGet the byte at the specified index.- Specified by:
getBytein interfaceByteBuffer<T>- Parameters:
index- The index- Returns:
- The byte
-