public class FileBuffer 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 |
---|
FileBuffer(File file,
int limit)
Constructs a new file 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 FileBuffer(File file, int limit) throws FileNotFoundException
file
- the file to use as storage for the buffer.limit
- the buffer length limit, after which an OverflowException
will be thrown.FileNotFoundException
- if the file cannot be created or opened for writing.SecurityException
- if a security manager denies access to the specified file.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, OverflowException
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() throws IOException
Buffer
length
in interface Buffer
IOException
- if an I/O exception occurs.public void close() throws IOException
Buffer
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Buffer
IOException
- if an I/O exception occurs.Copyright © 2014 ForgeRock AS. All rights reserved.