public class Volume
MapDB abstraction over raw storage (file, disk partition, memory etc...).
Implementations needs to be thread safe (especially 'ensureAvailable') operation. However updates do not have to be atomic, it is clients responsibility to ensure two threads are not writing/reading into the same location.
Modifier and Type | Field and Description |
---|---|
static java.util.logging.Logger |
LOG |
static VolumeFactory |
UNSAFE_VOL_FACTORY
If
sun.misc.Unsafe is available it will use Volume based on Unsafe. If Unsafe is not available for some reason (Android), use DirectByteBuffer instead. |
java.util.concurrent.atomic.AtomicBoolean |
closed |
Modifier and Type | Method and Description |
---|---|
void |
assertZeroes()
Check that all bytes between given offsets are zero. This might cross 1MB boundaries
|
void |
clear()
Set all bytes between
startOffset and endOffset to zero. Area between offsets must be ready for write once clear finishes. |
void |
clearOverlap() |
void |
close() |
void |
copyFrom()
Copy content from InputStream into this Volume.
|
void |
copyTo()
Transfers data from this Volume into target volume. If its possible, the implementation should override this method to enable direct memory transfer. Caller must respect slice boundaries. ie it is not possible to transfer data which cross slice boundaries.
|
void |
copyTo()
Copy content of this volume to another. Target volume might grow, but is never shrank. Target is also not synced
|
void |
copyTo()
Copy content of this volume to OutputStream.
|
void |
deleteFile() |
void |
ensureAvailable()
Check space allocated by Volume is bigger or equal to given offset. So it is safe to write into smaller offsets.
|
boolean |
fileLoad()
If underlying storage is memory-mapped-file, this method will try to load and precache all file data into disk cache. Most likely it will call
MappedByteBuffer#load() , but could also read content of entire file etc This method will not pin data into memory, they might be removed at any time. |
void |
finalize() |
byte |
getByte() |
void |
getData() |
DataInput2 |
getDataInput() |
DataInput2 |
getDataInputOverlap() |
java.io.File |
getFile()
returns underlying file if it exists
|
boolean |
getFileLocked()
return true if this Volume holds exclusive lock over its file
|
int |
getInt() |
long |
getLong() |
long |
getPackedLong()
Unpack long value from the Volume. Highest 4 bits reused to indicate number of bytes read from Volume. One can use
result & DataIO.PACK_LONG_RESULT_MASK to remove size; |
long |
getSixLong() |
int |
getUnsignedByte() |
int |
getUnsignedShort() |
long |
hash()
Calculates XXHash64 from this Volume content.
|
boolean |
isClosed() |
boolean |
isReadOnly() |
boolean |
isSliced() |
long |
length() |
void |
putByte() |
void |
putData() |
void |
putData() |
void |
putDataOverlap() |
void |
putInt() |
void |
putLong() |
int |
putPackedLong()
Put packed long at given position.
|
void |
putSixLong() |
void |
putUnsignedByte() |
void |
putUnsignedShort() |
int |
sliceSize() |
void |
sync() |
void |
truncate() |
public static java.util.logging.Logger LOG
public static VolumeFactory UNSAFE_VOL_FACTORY
If sun.misc.Unsafe
is available it will use Volume based on Unsafe. If Unsafe is not available for some reason (Android), use DirectByteBuffer instead.
public java.util.concurrent.atomic.AtomicBoolean closed
public boolean fileLoad()
If underlying storage is memory-mapped-file, this method will try to load and precache all file data into disk cache. Most likely it will call MappedByteBuffer#load()
, but could also read content of entire file etc This method will not pin data into memory, they might be removed at any time.
public void assertZeroes()
Check that all bytes between given offsets are zero. This might cross 1MB boundaries
DataCorruption
public boolean isClosed()
public void finalize()
public void ensureAvailable()
Check space allocated by Volume is bigger or equal to given offset. So it is safe to write into smaller offsets.
public void truncate()
public void putLong()
public void putInt()
public void putByte()
public void putData()
public void putData()
public void putDataOverlap()
public long getLong()
public int getInt()
public byte getByte()
public DataInput2 getDataInput()
public DataInput2 getDataInputOverlap()
public void getData()
public void close()
public void sync()
public int sliceSize()
public void deleteFile()
public boolean isSliced()
public long length()
public void putUnsignedShort()
public int getUnsignedShort()
public int getUnsignedByte()
public void putUnsignedByte()
public long getSixLong()
public void putSixLong()
public int putPackedLong()
Put packed long at given position.
public long getPackedLong()
Unpack long value from the Volume. Highest 4 bits reused to indicate number of bytes read from Volume. One can use result & DataIO.PACK_LONG_RESULT_MASK
to remove size;
public boolean isReadOnly()
public java.io.File getFile()
returns underlying file if it exists
public boolean getFileLocked()
return true if this Volume holds exclusive lock over its file
public void copyTo()
Transfers data from this Volume into target volume. If its possible, the implementation should override this method to enable direct memory transfer. Caller must respect slice boundaries. ie it is not possible to transfer data which cross slice boundaries.
public void clear()
Set all bytes between startOffset
and endOffset
to zero. Area between offsets must be ready for write once clear finishes.
public void clearOverlap()
public void copyTo()
Copy content of this volume to another. Target volume might grow, but is never shrank. Target is also not synced
public void copyFrom()
Copy content from InputStream into this Volume.
public void copyTo()
Copy content of this volume to OutputStream.
public long hash()
Calculates XXHash64 from this Volume content.