- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
AbstractPersistentBuffer,LargeMappedPersistentBuffer,MappedPersistentBuffer,RandomAccessFileBuffer,TwoCopyBarrierBuffer
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(boolean) 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(boolean) calls is not maintained.
- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionvoidbarrier(boolean force) Ensures that all writes before this barrier occur before all writes after this barrier.longcapacity()Gets the capacity of this buffer.voidclose()Closes this buffer.voidensureZeros(long position, long len) Ensures that all values from the position for the provided length are zeros.byteget(long position) Reads a byte at the provided position.voidget(long position, byte[] buff, int off, int len) Reads to the providedbyte[], starting at the provided position and for the designated number of bytes.booleangetBoolean(long position) Reads a boolean at the provided position, zero is consideredfalseand any non-zero value istrue.getInputStream(long position, long length) Gets an input stream that reads from this buffer.intgetInt(long position) Reads an integer at the provided position.longgetLong(long position) Reads a long at the provided position.getOutputStream(long position, long length) Gets an output stream that writes to this buffer.Gets the protection level currently enforced by the buffer.intgetSome(long position, byte[] buff, int off, int len) Reads to the providedbyte[], may read fewer thanlenbytes, but will always read at least one byte.booleanisClosed()Checks if this buffer is closed.voidput(long position, byte value) Puts a single value in the buffer.voidput(long position, byte[] buff, int off, int len) Writes the bytes to the provided position.voidputInt(long position, int value) Writes an integer at the provided position.voidputLong(long position, long value) Writes a long at the provided position.voidsetCapacity(long newCapacity) Sets the capacity of this buffer.
-
Method Details
-
isClosed
boolean isClosed()Checks if this buffer is closed. -
close
Closes this buffer. It is OK to close an already closed buffer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
capacity
Gets the capacity of this buffer.- Throws:
IOException
-
setCapacity
Sets the capacity of this buffer. If the buffer is increased in size, the new space will be zero-filled. Setting the capacity may impose an automaticbarrier(true), depending on implementation. This should be considered an expensive operation.- Throws:
IOException
-
get
Reads to the providedbyte[], starting at the provided position and for the designated number of bytes.- Throws:
BufferUnderflowException- on end of fileIOException
-
getSome
Reads to the providedbyte[], may read fewer thanlenbytes, but will always read at least one byte. Blocks if no data is available.- Throws:
BufferUnderflowException- on end of fileIOException
-
getBoolean
Reads a boolean at the provided position, zero is consideredfalseand any non-zero value istrue.- Throws:
IOException
-
get
Reads a byte at the provided position.- Throws:
IOException
-
getInt
Reads an integer at the provided position.- Throws:
IOException
-
getLong
Reads a long at the provided position.- Throws:
IOException
-
ensureZeros
Ensures that all values from the position for the provided length are zeros. This may or may not modify the buffer in the process. The values will all be zero upon return. Some implementations may choose to overwrite zeros and return modified, others may choose to detect zeros and avoid modifications. Thus it is possible for existing zeros to still result in a modification.- Throws:
IOException
-
put
Puts a single value in the buffer.- Throws:
IOException
-
put
Writes the bytes to the provided position. The buffer will not be expanded automatically.- Throws:
BufferOverflowException- on end of fileIOException
-
putInt
Writes an integer at the provided position. The buffer will not be expanded automatically.- Throws:
BufferOverflowException- on end of fileIOException
-
putLong
Writes a long at the provided position. The buffer will not be expanded automatically.- Throws:
BufferOverflowException- on end of fileIOException
-
getProtectionLevel
ProtectionLevel getProtectionLevel()Gets the protection level currently enforced by the buffer.- See Also:
-
barrier
Ensures that all writes before this barrier occur before all writes after this barrier. Ifforceistrue, 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.- Throws:
IOException- See Also:
-
getInputStream
Gets an input stream that reads from this buffer. Bounds checking is performed.- Throws:
BufferUnderflowException- on end of fileIOException
-
getOutputStream
OutputStream getOutputStream(long position, long length) throws IOException, BufferOverflowException Gets an output stream that writes to this buffer. Bounds checking is performed.- Throws:
BufferUnderflowException- on end of fileIOExceptionBufferOverflowException
-
