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
ConstructorsConstructorDescriptionCreates a read-write buffer backed by a temporary file.RandomAccessFileBuffer(File file) Creates a read-write buffer withProtectionLevel.BARRIERprotection 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.BARRIERprotection level.RandomAccessFileBuffer(String name, ProtectionLevel protectionLevel) Creates a buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoidbarrier(boolean force) There is not currently a way to provide a barrier without usingforce.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) Gets a single byte from 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 byte in the buffer.voidput(long position, byte[] buff, int off, int len) Writes the bytes to the provided position.voidsetCapacity(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.BARRIERprotection level.- Throws:
IOException
-
RandomAccessFileBuffer
Creates a buffer.- Throws:
IOException
-
RandomAccessFileBuffer
Creates a read-write buffer withProtectionLevel.BARRIERprotection 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:PersistentBufferChecks if this buffer is closed. -
close
Description copied from interface:PersistentBufferCloses this buffer. It is OK to close an already closed buffer.- Throws:
IOException
-
capacity
Description copied from interface:PersistentBufferGets the capacity of this buffer.- Throws:
IOException
-
setCapacity
Description copied from interface:PersistentBufferSets 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:PersistentBufferReads to the providedbyte[], may read fewer thanlenbytes, 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:
getin interfacePersistentBuffer- Overrides:
getin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
ensureZeros
Description copied from interface:PersistentBufferEnsures 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:
putin interfacePersistentBuffer- Overrides:
putin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
put
Description copied from interface:PersistentBufferWrites 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:
-
