Class Volume
- java.lang.Object
-
- org.mapdb.Volume
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable
- Direct Known Subclasses:
- Volume.ByteArrayVol, Volume.ByteBufferVol, Volume.ByteBufferVolSingle, Volume.FileChannelVol, Volume.RandomAccessFileVol, Volume.ReadOnly, Volume.SingleByteArrayVol
public abstract class Volume extends java.lang.Object implements java.io.CloseableMapDB 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classVolume.ByteArrayVolstatic classVolume.ByteBufferVolAbstract Volume over bunch of ByteBuffers It leaves ByteBufferVol details (allocation, disposal) on subclasses.static classVolume.ByteBufferVolSingleAbstract Volume over single ByteBuffer, maximal size is 2GB (32bit limit).static classVolume.FileChannelVolVolume which uses FileChannel.static classVolume.MappedFileVolstatic classVolume.MappedFileVolSinglestatic classVolume.MemoryVolstatic classVolume.MemoryVolSinglestatic classVolume.RandomAccessFileVolstatic classVolume.ReadOnlystatic classVolume.SingleByteArrayVolVolume backed by on-heap byte[] with maximal fixed size 2GB.static classVolume.VolumeFactory
-
Field Summary
Fields Modifier and Type Field and Description static Volume.VolumeFactoryUNSAFE_VOL_FACTORYIfsun.misc.Unsafeis available it will use Volume based on Unsafe.
-
Constructor Summary
Constructors Constructor and Description Volume()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract voidclear(long startOffset, long endOffset)Set all bytes betweenstartOffsetandendOffsetto zero.abstract voidclose()voidcopyEntireVolumeTo(Volume to)Copy content of this volume to another.voiddeleteFile()abstract voidensureAvailable(long offset)Check space allocated by Volume is bigger or equal to given offset.booleanfileLoad()If underlying storage is memory-mapped-file, this method will try to load and precache all file data into disk cache.abstract bytegetByte(long offset)abstract voidgetData(long offset, byte[] bytes, int bytesPos, int size)abstract java.io.DataInputgetDataInput(long offset, int size)java.io.DataInputgetDataInputOverlap(long offset, int size)abstract java.io.FilegetFile()returns underlying file if it existsabstract booleangetFileLocked()return true if this Volume holds exclusive lock over its fileabstract intgetInt(long offset)abstract longgetLong(long offset)longgetLongPackBidi(long offset)longgetLongPackBidiReverse(long offset)longgetPackedLong(long position)Unpack long value from the Volume.longgetSixLong(long pos)intgetUnsignedByte(long offset)intgetUnsignedShort(long offset)longhash(long off, long len, long seed)Calculates XXHash64 from this Volume content.booleanisClosed()abstract booleanisSliced()abstract longlength()abstract voidputByte(long offset, byte value)abstract voidputData(long offset, byte[] src, int srcPos, int srcSize)abstract voidputData(long offset, java.nio.ByteBuffer buf)voidputDataOverlap(long offset, byte[] src, int srcPos, int srcSize)abstract voidputInt(long offset, int value)abstract voidputLong(long offset, long value)intputLongPackBidi(long offset, long value)intputPackedLong(long pos, long value)Put packed long at given position.voidputSixLong(long pos, long value)voidputUnsignedByte(long offset, int b)voidputUnsignedShort(long offset, int value)abstract intsliceSize()abstract voidsync()voidtransferInto(long inputOffset, Volume target, long targetOffset, long size)Transfers data from this Volume into target volume.abstract voidtruncate(long size)static voidvolumeTransfer(long size, Volume from, Volume to)transfer data from one volume to second.
-
-
-
Field Detail
-
UNSAFE_VOL_FACTORY
public static final Volume.VolumeFactory UNSAFE_VOL_FACTORY
Ifsun.misc.Unsafeis available it will use Volume based on Unsafe. If Unsafe is not available for some reason (Android), use DirectByteBuffer instead.
-
-
Method Detail
-
fileLoad
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.- Returns:
- true if this method did something, false if underlying storage does not support loading
-
isClosed
public boolean isClosed()
-
ensureAvailable
public abstract void ensureAvailable(long offset)
Check space allocated by Volume is bigger or equal to given offset. So it is safe to write into smaller offsets.- Parameters:
offset-
-
truncate
public abstract void truncate(long size)
-
putLong
public abstract void putLong(long offset, long value)
-
putInt
public abstract void putInt(long offset, int value)
-
putByte
public abstract void putByte(long offset, byte value)
-
putData
public abstract void putData(long offset, byte[] src, int srcPos, int srcSize)
-
putData
public abstract void putData(long offset, java.nio.ByteBuffer buf)
-
putDataOverlap
public void putDataOverlap(long offset, byte[] src, int srcPos, int srcSize)
-
getLong
public abstract long getLong(long offset)
-
getInt
public abstract int getInt(long offset)
-
getByte
public abstract byte getByte(long offset)
-
getDataInput
public abstract java.io.DataInput getDataInput(long offset, int size)
-
getDataInputOverlap
public java.io.DataInput getDataInputOverlap(long offset, int size)
-
getData
public abstract void getData(long offset, byte[] bytes, int bytesPos, int size)
-
close
public abstract void close()
- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable
-
sync
public abstract void sync()
-
sliceSize
public abstract int sliceSize()
- Returns:
- slice size or
-1if not sliced
-
deleteFile
public void deleteFile()
-
isSliced
public abstract boolean isSliced()
-
length
public abstract long length()
-
putUnsignedShort
public void putUnsignedShort(long offset, int value)
-
getUnsignedShort
public int getUnsignedShort(long offset)
-
getUnsignedByte
public int getUnsignedByte(long offset)
-
putUnsignedByte
public void putUnsignedByte(long offset, int b)
-
putLongPackBidi
public int putLongPackBidi(long offset, long value)
-
getLongPackBidi
public long getLongPackBidi(long offset)
-
getLongPackBidiReverse
public long getLongPackBidiReverse(long offset)
-
getSixLong
public long getSixLong(long pos)
-
putSixLong
public void putSixLong(long pos, long value)
-
putPackedLong
public int putPackedLong(long pos, long value)Put packed long at given position.- Parameters:
value- to be written- Returns:
- number of bytes consumed by packed value
-
getPackedLong
public long getPackedLong(long position)
Unpack long value from the Volume. Highest 4 bits reused to indicate number of bytes read from Volume. One can useresult & DataIO.PACK_LONG_RESULT_MASKto remove size;- Parameters:
position- to read value from- Returns:
- The long value, minus highest byte
-
getFile
public abstract java.io.File getFile()
returns underlying file if it exists
-
getFileLocked
public abstract boolean getFileLocked()
return true if this Volume holds exclusive lock over its file
-
transferInto
public void transferInto(long inputOffset, Volume target, long targetOffset, long size)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.- Parameters:
inputOffset- offset inside this Volume, ie data will be read from this offsettarget- Volume to copy data intotargetOffset- position in target volume where data will be copied intosize- size of data to copy
-
clear
public abstract void clear(long startOffset, long endOffset)Set all bytes betweenstartOffsetandendOffsetto zero. Area between offsets must be ready for write once clear finishes.
-
copyEntireVolumeTo
public void copyEntireVolumeTo(Volume to)
Copy content of this volume to another. Target volume might grow, but is never shrank. Target is also not synced
-
hash
public long hash(long off, long len, long seed)Calculates XXHash64 from this Volume content.
This code comes from LZ4-Java created by Adrien Grand.
- Parameters:
off- offset to start calculation fromlen- length of data to calculate hashseed- hash seed- Returns:
- XXHash.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG