- java.lang.Object
-
- com.aoapps.persistence.AbstractPersistentBuffer
-
- com.aoapps.persistence.LargeMappedPersistentBuffer
-
- All Implemented Interfaces:
PersistentBuffer
,Closeable
,AutoCloseable
public class LargeMappedPersistentBuffer extends AbstractPersistentBuffer
Uses a set ofMappedByteBuffer
for persistence. Each buffer covers a maximum of 2^30 bytes. This handles mapping of up to 2^30 * 2^31-2 bytes.- Author:
- AO Industries, Inc.
- See Also:
MappedPersistentBuffer
-
-
Field Summary
-
Fields inherited from class com.aoapps.persistence.AbstractPersistentBuffer
protectionLevel
-
-
Constructor Summary
Constructors Constructor Description LargeMappedPersistentBuffer()
Creates a read-write buffer backed by a temporary file.LargeMappedPersistentBuffer(File file)
Creates a read-write buffer withProtectionLevel.BARRIER
protection level.LargeMappedPersistentBuffer(File file, ProtectionLevel protectionLevel)
Creates a buffer.LargeMappedPersistentBuffer(RandomAccessFile raf, ProtectionLevel protectionLevel)
Creates a buffer using the providedRandomAccessFile
.LargeMappedPersistentBuffer(String name)
Creates a read-write buffer withProtectionLevel.BARRIER
protection level.LargeMappedPersistentBuffer(String name, ProtectionLevel protectionLevel)
Creates a buffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.void
get(long position, byte[] buff, int off, int len)
Implemented as calls toPersistentBuffer.getSome(long, byte[], int, int)
.boolean
getBoolean(long position)
Implemented as call toAbstractPersistentBuffer.get(long)
.int
getInt(long position)
Implemented as call toAbstractPersistentBuffer.get(long, byte[], int, int)
.long
getLong(long position)
Implemented as call toAbstractPersistentBuffer.get(long, byte[], int, int)
.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
putInt(long position, int value)
Implemented as call toPersistentBuffer.put(long, byte[], int, int)
.void
putLong(long position, long value)
Implemented as call toPersistentBuffer.put(long, byte[], int, int)
.void
setCapacity(long newLength)
Sets the capacity of this buffer.-
Methods inherited from class com.aoapps.persistence.AbstractPersistentBuffer
getInputStream, getOutputStream, getProtectionLevel
-
-
-
-
Constructor Detail
-
LargeMappedPersistentBuffer
public LargeMappedPersistentBuffer() throws IOException
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
-
LargeMappedPersistentBuffer
public LargeMappedPersistentBuffer(String name) throws IOException
Creates a read-write buffer withProtectionLevel.BARRIER
protection level.- Throws:
IOException
-
LargeMappedPersistentBuffer
public LargeMappedPersistentBuffer(String name, ProtectionLevel protectionLevel) throws IOException
Creates a buffer.- Throws:
IOException
-
LargeMappedPersistentBuffer
public LargeMappedPersistentBuffer(File file) throws IOException
Creates a read-write buffer withProtectionLevel.BARRIER
protection level.- Throws:
IOException
-
LargeMappedPersistentBuffer
public LargeMappedPersistentBuffer(File file, ProtectionLevel protectionLevel) throws IOException
Creates a buffer.- Throws:
IOException
-
LargeMappedPersistentBuffer
public LargeMappedPersistentBuffer(RandomAccessFile raf, ProtectionLevel protectionLevel) throws IOException
Creates a buffer using the providedRandomAccessFile
.- Throws:
IOException
-
-
Method Detail
-
isClosed
public boolean isClosed()
Description copied from interface:PersistentBuffer
Checks if this buffer is closed.
-
close
public void close() throws IOException
Description copied from interface:PersistentBuffer
Closes this buffer. It is OK to close an already closed buffer.- Throws:
IOException
-
capacity
public long capacity() throws IOException
Description copied from interface:PersistentBuffer
Gets the capacity of this buffer.- Throws:
IOException
-
setCapacity
public void setCapacity(long newLength) throws IOException
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
-
get
public void get(long position, byte[] buff, int off, int len) throws IOException
Description copied from class:AbstractPersistentBuffer
Implemented as calls toPersistentBuffer.getSome(long, byte[], int, int)
.- Specified by:
get
in interfacePersistentBuffer
- Overrides:
get
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
PersistentBuffer.getSome(long, byte[], int, int)
-
getSome
public int getSome(long position, byte[] buff, int off, int len) throws IOException
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
public byte get(long position) throws IOException
Gets a single byte from the buffer.- Specified by:
get
in interfacePersistentBuffer
- Overrides:
get
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
AbstractPersistentBuffer.get(long, byte[], int, int)
-
ensureZeros
public void ensureZeros(long position, long len) throws IOException
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
public void put(long position, byte value) throws IOException
Puts a single byte in the buffer.- Specified by:
put
in interfacePersistentBuffer
- Overrides:
put
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
PersistentBuffer.put(long, byte[], int, int)
-
put
public void put(long position, byte[] buff, int off, int len) throws IOException
Description copied from interface:PersistentBuffer
Writes the bytes to the provided position. The buffer will not be expanded automatically.- Throws:
IOException
-
barrier
public void barrier(boolean force) throws IOException
There is not currently a way to provide a barrier without usingforce
. This just uses force for both.- Throws:
IOException
- See Also:
PersistentBuffer.getProtectionLevel()
-
getBoolean
public boolean getBoolean(long position) throws IOException
Description copied from class:AbstractPersistentBuffer
Implemented as call toAbstractPersistentBuffer.get(long)
.- Specified by:
getBoolean
in interfacePersistentBuffer
- Overrides:
getBoolean
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
AbstractPersistentBuffer.get(long)
-
getInt
public int getInt(long position) throws IOException
Description copied from class:AbstractPersistentBuffer
Implemented as call toAbstractPersistentBuffer.get(long, byte[], int, int)
.- Specified by:
getInt
in interfacePersistentBuffer
- Overrides:
getInt
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
AbstractPersistentBuffer.get(long, byte[], int, int)
-
getLong
public long getLong(long position) throws IOException
Description copied from class:AbstractPersistentBuffer
Implemented as call toAbstractPersistentBuffer.get(long, byte[], int, int)
.- Specified by:
getLong
in interfacePersistentBuffer
- Overrides:
getLong
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
AbstractPersistentBuffer.get(long, byte[], int, int)
-
putInt
public void putInt(long position, int value) throws IOException
Description copied from class:AbstractPersistentBuffer
Implemented as call toPersistentBuffer.put(long, byte[], int, int)
.- Specified by:
putInt
in interfacePersistentBuffer
- Overrides:
putInt
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
PersistentBuffer.put(long, byte[], int, int)
-
putLong
public void putLong(long position, long value) throws IOException
Description copied from class:AbstractPersistentBuffer
Implemented as call toPersistentBuffer.put(long, byte[], int, int)
.- Specified by:
putLong
in interfacePersistentBuffer
- Overrides:
putLong
in classAbstractPersistentBuffer
- Throws:
IOException
- See Also:
PersistentBuffer.put(long, byte[], int, int)
-
-