public class TemporaryBuffer extends Object implements Buffer
MemoryBuffer
is used; when the memory buffer limit is exceeded it promotes to
the use of a FileBuffer
.Constructor and Description |
---|
TemporaryBuffer(int initialLength,
int memoryLimit,
int fileLimit,
File directory)
Constructs a new temporary 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.
|
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 TemporaryBuffer(int initialLength, int memoryLimit, int fileLimit, File directory)
initialLength
- the initial length of memory buffer byte array.memoryLimit
- the length limit of the memory buffer.fileLimit
- the length limit of the file buffer.directory
- the directory where temporary files are created, or null
to use the system-dependent
default temporary directory.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.