public class MemoryBuffer extends Object implements Buffer
Note: This implementation is not synchronized. If multiple threads access a buffer concurrently, threads that append to the buffer should synchronize on the instance of this object.
Constructor and Description |
---|
MemoryBuffer(int initial,
int limit)
Constructs a new memory buffer.
|
Modifier and Type | Method and Description |
---|---|
void |
append(byte[] b,
int off,
int len)
Appends
len bytes from the specified byte array starting at offset off
to the end of the buffer. |
void |
close()
Closes the buffer and releases any system resources associated with it.
|
void |
finalize() |
int |
length()
Returns the current length of the buffer.
|
int |
read(int pos,
byte[] b,
int off,
int len)
Reads up to
len bytes of data from the buffer into an array of bytes. |
public MemoryBuffer(int initial, int limit)
initial
- the initial size of the byte array to create.limit
- the buffer length limit, after which an OverflowException
will be thrown.public int read(int pos, byte[] b, int off, int len) throws IOException
Buffer
len
bytes of data from the buffer into an array of bytes. An
attempt is made to read as many as len
bytes, but a smaller number may be read.
The number of bytes actually read is returned as an integer.read
in interface Buffer
pos
- the offset position, measured in bytes from the beginning of the buffer, at which to read the data.b
- the array of bytes to write the data to.off
- the start offset in the array at which the data is written.len
- the maximum number of bytes to read.IOException
- if an I/O exception occurs.public void append(byte[] b, int off, int len) throws IOException
Buffer
len
bytes from the specified byte array starting at offset off
to the end of the buffer.append
in interface Buffer
b
- the array of bytes to read the data from.off
- the start offset in the array at which the data is read.len
- the number of bytes to be appended to the buffer.IOException
- if an I/O exception occurs.OverflowException
- if appending len
bytes to the buffer would exceed its limit.public int length()
Buffer
public void close()
Buffer
Copyright © 2014 ForgeRock AS. All rights reserved.