java.lang.Object
com.aoapps.persistence.AbstractPersistentBuffer
com.aoapps.persistence.RandomAccessFileBuffer
- All Implemented Interfaces:
PersistentBuffer
,Closeable
,AutoCloseable
Uses
RandomAccessFile
for persistence. Obtains a shared lock
on the channel for read-only mode or an exclusive lock for write mode. The
lock is held until the buffer is closed.- Author:
- AO Industries, Inc.
-
Field Summary
Fields inherited from class com.aoapps.persistence.AbstractPersistentBuffer
protectionLevel
-
Constructor Summary
ConstructorDescriptionCreates a read-write buffer backed by a temporary file.RandomAccessFileBuffer
(File file) Creates a read-write buffer withProtectionLevel.BARRIER
protection level.RandomAccessFileBuffer
(File file, ProtectionLevel protectionLevel) Creates a buffer.RandomAccessFileBuffer
(RandomAccessFile raf, ProtectionLevel protectionLevel) Creates a buffer using the providedRandomAccessFile
.RandomAccessFileBuffer
(String name) Creates a read-write buffer withProtectionLevel.BARRIER
protection level.RandomAccessFileBuffer
(String name, ProtectionLevel protectionLevel) Creates a buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
barrier
(boolean force) There is not currently a way to provide a barrier without usingforce
.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) Gets a single byte from the buffer.int
getSome
(long position, byte[] buff, int off, int len) Reads to the providedbyte[]
, may read fewer thanlen
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 byte in the buffer.void
put
(long position, byte[] buff, int off, int len) Writes the bytes to the provided position.void
setCapacity
(long newLength) Sets the capacity of this buffer.Methods inherited from class com.aoapps.persistence.AbstractPersistentBuffer
get, getBoolean, getInputStream, getInt, getLong, getOutputStream, getProtectionLevel, putInt, putLong
-
Constructor Details
-
RandomAccessFileBuffer
Creates a read-write buffer backed by a temporary file. The protection level is set toProtectionLevel.NONE
. The temporary file will be deleted when this buffer is closed or on JVM shutdown.- Throws:
IOException
-
RandomAccessFileBuffer
Creates a read-write buffer withProtectionLevel.BARRIER
protection level.- Throws:
IOException
-
RandomAccessFileBuffer
Creates a buffer.- Throws:
IOException
-
RandomAccessFileBuffer
Creates a read-write buffer withProtectionLevel.BARRIER
protection level.- Throws:
IOException
-
RandomAccessFileBuffer
Creates a buffer.- Throws:
IOException
-
RandomAccessFileBuffer
public RandomAccessFileBuffer(RandomAccessFile raf, ProtectionLevel protectionLevel) throws IOException Creates a buffer using the providedRandomAccessFile
.- Throws:
IOException
-
-
Method Details
-
isClosed
public boolean isClosed()Description copied from interface:PersistentBuffer
Checks if this buffer is closed. -
close
Description copied from interface:PersistentBuffer
Closes this buffer. It is OK to close an already closed buffer.- Throws:
IOException
-
capacity
Description copied from interface:PersistentBuffer
Gets the capacity of this buffer.- Throws:
IOException
-
setCapacity
Description copied from interface:PersistentBuffer
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
-
getSome
Description copied from interface:PersistentBuffer
Reads to the providedbyte[]
, may read fewer thanlen
bytes, but will always read at least one byte. Blocks if no data is available.- Throws:
IOException
-
get
Gets a single byte from the buffer.- Specified by:
get
in interfacePersistentBuffer
- Overrides:
get
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
-
ensureZeros
Description copied from interface:PersistentBuffer
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 byte in the buffer.- Specified by:
put
in interfacePersistentBuffer
- Overrides:
put
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
-
put
Description copied from interface:PersistentBuffer
Writes the bytes to the provided position. The buffer will not be expanded automatically.- Throws:
IOException
-
barrier
There is not currently a way to provide a barrier without usingforce
. This just uses force for each case.- Throws:
IOException
- See Also:
-