java.lang.Object
com.aoapps.persistence.AbstractPersistentBuffer
com.aoapps.persistence.MappedPersistentBuffer
- All Implemented Interfaces:
PersistentBuffer,Closeable,AutoCloseable
Uses
MappedByteBuffer for persistence. It maps the entire file
at once into a single buffer. For this reason, it is limited to a maximum
buffer size of 2^31-1. To use memory mapping for larger buffers, at a slight
performance cost, use LargeMappedPersistentBuffer.- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Fields inherited from class com.aoapps.persistence.AbstractPersistentBuffer
protectionLevel -
Constructor Summary
ConstructorsConstructorDescriptionCreates a read-write buffer backed by a temporary file.MappedPersistentBuffer(File file) Creates a read-write buffer withProtectionLevel.BARRIERprotection level.MappedPersistentBuffer(File file, ProtectionLevel protectionLevel) Creates a buffer.MappedPersistentBuffer(RandomAccessFile raf, ProtectionLevel protectionLevel) Creates a buffer using the providedRandomAccessFile.MappedPersistentBuffer(String name) Creates a read-write buffer withProtectionLevel.BARRIERprotection level.MappedPersistentBuffer(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.voidget(long position, byte[] buff, int off, int len) Implemented as calls toPersistentBuffer.getSome(long, byte[], int, int).booleangetBoolean(long position) Implemented as call toAbstractPersistentBuffer.get(long).intgetInt(long position) Implemented as call toAbstractPersistentBuffer.get(long, byte[], int, int).longgetLong(long position) Implemented as call toAbstractPersistentBuffer.get(long, byte[], int, int).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.voidputInt(long position, int value) Implemented as call toPersistentBuffer.put(long, byte[], int, int).voidputLong(long position, long value) Implemented as call toPersistentBuffer.put(long, byte[], int, int).voidsetCapacity(long newLength) Sets the capacity of this buffer.Methods inherited from class com.aoapps.persistence.AbstractPersistentBuffer
getInputStream, getOutputStream, getProtectionLevel
-
Constructor Details
-
MappedPersistentBuffer
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
-
MappedPersistentBuffer
Creates a read-write buffer withProtectionLevel.BARRIERprotection level.- Throws:
IOException
-
MappedPersistentBuffer
Creates a buffer.- Throws:
IOException
-
MappedPersistentBuffer
Creates a read-write buffer withProtectionLevel.BARRIERprotection level.- Throws:
IOException
-
MappedPersistentBuffer
Creates a buffer.- Throws:
IOException
-
MappedPersistentBuffer
public MappedPersistentBuffer(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
-
get
Description copied from class:AbstractPersistentBufferImplemented as calls toPersistentBuffer.getSome(long, byte[], int, int).- Specified by:
getin interfacePersistentBuffer- Overrides:
getin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
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 both.- Throws:
IOException- See Also:
-
getBoolean
Description copied from class:AbstractPersistentBufferImplemented as call toAbstractPersistentBuffer.get(long).- Specified by:
getBooleanin interfacePersistentBuffer- Overrides:
getBooleanin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
getInt
Description copied from class:AbstractPersistentBufferImplemented as call toAbstractPersistentBuffer.get(long, byte[], int, int).- Specified by:
getIntin interfacePersistentBuffer- Overrides:
getIntin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
getLong
Description copied from class:AbstractPersistentBufferImplemented as call toAbstractPersistentBuffer.get(long, byte[], int, int).- Specified by:
getLongin interfacePersistentBuffer- Overrides:
getLongin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
putInt
Description copied from class:AbstractPersistentBufferImplemented as call toPersistentBuffer.put(long, byte[], int, int).- Specified by:
putIntin interfacePersistentBuffer- Overrides:
putIntin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
putLong
Description copied from class:AbstractPersistentBufferImplemented as call toPersistentBuffer.put(long, byte[], int, int).- Specified by:
putLongin interfacePersistentBuffer- Overrides:
putLongin classAbstractPersistentBuffer- Throws:
IOException- See Also:
-
