Package org.forgerock.http.io
Interface Buffer
-
- All Superinterfaces:
AutoCloseable
,Closeable
public interface Buffer extends Closeable
A dynamically growing data buffer. Data can be read from any point within the buffer, and written to the end of a buffer.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
append(byte b)
Appends a single byte to the end of the buffer.void
append(byte[] b, int off, int len)
Appendslen
bytes from the specified byte array starting at offsetoff
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.byte
read(int pos)
Reads a single byte of data from the buffer.int
read(int pos, byte[] b, int off, int len)
Reads up tolen
bytes of data from the buffer into an array of bytes.
-
-
-
Method Detail
-
read
byte read(int pos) throws IOException
Reads a single byte of data from the buffer.- Parameters:
pos
- the offset position, measured in bytes from the beginning of the buffer, at which to read the data.- Returns:
- byte at given offset position.
- Throws:
IOException
- if an I/O exception occurs.IndexOutOfBoundsException
- ifpos
exceeds the buffer length.
-
read
int read(int pos, byte[] b, int off, int len) throws IOException
Reads up tolen
bytes of data from the buffer into an array of bytes. An attempt is made to read as many aslen
bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.- Parameters:
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.- Returns:
- the number of bytes read into the array.
- Throws:
IOException
- if an I/O exception occurs.
-
append
void append(byte b) throws IOException
Appends a single byte to the end of the buffer.- Parameters:
b
- the byte to append.- Throws:
IOException
- if an I/O exception occurs.OverflowException
- if appending a single byte to the buffer would exceed its limit.
-
append
void append(byte[] b, int off, int len) throws IOException
Appendslen
bytes from the specified byte array starting at offsetoff
to the end of the buffer.- Parameters:
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.- Throws:
IOException
- if an I/O exception occurs.OverflowException
- if appendinglen
bytes to the buffer would exceed its limit.
-
length
int length() throws IOException
Returns the current length of the buffer.- Returns:
- the length of the file, measured in bytes.
- Throws:
IOException
- if an I/O exception occurs.
-
close
void close() throws IOException
Closes the buffer and releases any system resources associated with it. A closed buffer cannot perform input or output operations and cannot be reopened.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O exception occurs.
-
-