public class Buffer extends Object
Specialized ByteBuffer which will dynamically resize, maintain state and call the underlying ByteChannel as necessary to return the required amount of bytes.
Buffer also focuses on offering the capability to get bytes through multiple channels and place into one.
Constructor and Description |
---|
Buffer(int minimumSizeOfBuffer) |
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
get(int numberOfBytesRequested,
Channel channel)
Get readable byte buffer.
|
void |
reverse(int count)
Will reverse the position of the buffer.
|
public void reverse(int count) throws BallerinaIOException
Will reverse the position of the buffer.
This will reverse the un-processed bytes so that these bytes could be re-read.
Reverse will start from the current buffers read position and will go all the way to the position '0'.
count
- the number of bytes which should be reversed.BallerinaIOException
public ByteBuffer get(int numberOfBytesRequested, Channel channel) throws IOException
Get readable byte buffer.
If the bytes are not available in the buffer, an attempt would be made to get from the channel, best effort will be taken to return the required amount of bytes. If bytes are not available in both the buffer the maximum available bytes will be returned.
If bytes have being read previously through the buffer and the requested amount of bytes exceed the capacity of the current buffer. The buffer will be re-sized.
The operation will return slice of the bytes requested. The size of the buffer returned would be = numberOfBytesRequested. If numberOfBytesRequested < minimumSizeOfBuffer the size of the buffer will be minimumSizeOfBuffer
numberOfBytesRequested
- number of bytes requested from the buffer.channel
- byte channel which will perform I/O ops necessary for reading.IOException
- errors which occur while reading from the channel.Copyright © 2018 WSO2. All rights reserved.