Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public interface PersistentBuffer
A persistent buffer retains its data between uses. They should not be used by multiple virtual machines or even multiple instances within the same virtual machine. They are meant for persistence only, not interprocess communication.
To ensure the data integrity of higher-level data structures, the barrier method
must be used. A barrier ensures that all writes before the barrier happen before
all writes after the barrier. It also accepts a parameter indicating it should
also force (fsync) all writes before the barrier to physical media. Write order
between barrier calls is not maintained.
| Modifier and Type | Method and Description |
|---|---|
void |
barrier(boolean force)
Ensures that all writes before this barrier occur before all writes after
this barrier.
|
long |
capacity()
Gets the capacity of this buffer.
|
void |
close()
Closes this buffer.
|
void |
ensureZeros(long position,
long len)
Ensures that all values from the position for the provided length
are zeros.
|
byte |
get(long position)
Reads a byte at the provided position.
|
void |
get(long position,
byte[] buff,
int off,
int len)
Reads to the provided
byte[], starting at the provided
position and for the designated number of bytes. |
boolean |
getBoolean(long position)
Reads a boolean at the provided position, zero is considered
false
and any non-zero value is true. |
InputStream |
getInputStream(long position,
long length)
Gets an input stream that reads from this buffer.
|
int |
getInt(long position)
Reads an integer at the provided position.
|
long |
getLong(long position)
Reads a long at the provided position.
|
OutputStream |
getOutputStream(long position,
long length)
Gets an output stream that writes to this buffer.
|
ProtectionLevel |
getProtectionLevel()
Gets the protection level currently enforced by the buffer.
|
int |
getSome(long position,
byte[] buff,
int off,
int len)
Reads to the provided
byte[], may read fewer than len
bytes, but will always read at least one byte. |
boolean |
isClosed()
Checks if this buffer is closed.
|
void |
put(long position,
byte value)
Puts a single value in the buffer.
|
void |
put(long position,
byte[] buff,
int off,
int len)
Writes the bytes to the provided position.
|
void |
putInt(long position,
int value)
Writes an integer at the provided position.
|
void |
putLong(long position,
long value)
Writes a long at the provided position.
|
void |
setCapacity(long newCapacity)
Sets the capacity of this buffer.
|
boolean isClosed()
void close()
throws IOException
IOExceptionlong capacity()
throws IOException
IOExceptionvoid setCapacity(long newCapacity)
throws IOException
barrier(true), depending on implementation. This
should be considered an expensive operation.IOExceptionvoid get(long position,
byte[] buff,
int off,
int len)
throws IOException
byte[], starting at the provided
position and for the designated number of bytes.BufferUnderflowException - on end of fileIOExceptionint getSome(long position,
byte[] buff,
int off,
int len)
throws IOException
byte[], may read fewer than len
bytes, but will always read at least one byte. Blocks if no data is
available.BufferUnderflowException - on end of fileIOExceptionboolean getBoolean(long position)
throws IOException
false
and any non-zero value is true.IOExceptionbyte get(long position) throws IOException
IOExceptionint getInt(long position)
throws IOException
IOExceptionlong getLong(long position)
throws IOException
IOExceptionvoid ensureZeros(long position,
long len)
throws IOException
IOExceptionvoid put(long position,
byte value)
throws IOException
IOExceptionvoid put(long position,
byte[] buff,
int off,
int len)
throws IOException
BufferOverflowException - on end of fileIOExceptionvoid putInt(long position,
int value)
throws IOException
BufferOverflowException - on end of fileIOExceptionvoid putLong(long position,
long value)
throws IOException
BufferOverflowException - on end of fileIOExceptionProtectionLevel getProtectionLevel()
barrier(boolean)void barrier(boolean force)
throws IOException
force is true, will also
commit to physical media synchronously before returning. This request
may be ignored or force downgraded to barrier-only depending on the current
protection level.IOExceptiongetProtectionLevel()InputStream getInputStream(long position, long length) throws IOException, BufferUnderflowException
BufferUnderflowExceptionIOExceptionOutputStream getOutputStream(long position, long length) throws IOException, BufferOverflowException
BufferOverflowExceptionIOExceptionCopyright © 2000–2016 AO Industries, Inc.. All rights reserved.