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 voidappend(byte b)Appends a single byte to the end of the buffer.voidappend(byte[] b, int off, int len)Appendslenbytes from the specified byte array starting at offsetoffto the end of the buffer.voidclose()Closes the buffer and releases any system resources associated with it.intlength()Returns the current length of the buffer.byteread(int pos)Reads a single byte of data from the buffer.intread(int pos, byte[] b, int off, int len)Reads up tolenbytes 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- ifposexceeds the buffer length.
-
read
int read(int pos, byte[] b, int off, int len) throws IOExceptionReads up tolenbytes of data from the buffer into an array of bytes. An attempt is made to read as many aslenbytes, 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 IOExceptionAppends 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 IOExceptionAppendslenbytes from the specified byte array starting at offsetoffto 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 appendinglenbytes to the buffer would exceed its limit.
-
length
int length() throws IOExceptionReturns 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 IOExceptionCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O exception occurs.
-
-