Package com._1c.g5.v8.xmdb.impl
Class Volume
- java.lang.Object
-
- com._1c.g5.v8.xmdb.impl.Volume
-
public class Volume extends Object
Wrapper around file with databse
-
-
Field Summary
Fields Modifier and Type Field Description protected FileChannel
fc
protected File
file
protected RandomAccessFile
raf
protected boolean
readOnly
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close volumestatic void
copyFile(File sourceFile, File destFile)
Copy file with all its contentsvoid
drop()
Drop volume (close and delete from disc)byte
getByte(long offset)
Read byte value from volumeint
getData(long offset, ByteBuffer bytes, int bytesPos, int size)
Read data from volumeFile
getFile()
Get volume fileint
getInt(long offset)
Read integer value from volumelong
getLong(long offset)
Read long value from volumeboolean
isEmpty()
Test is volume empty (have zero size)long
length()
Get length of volumevoid
putByte(long offset, byte value)
Put byte value into volumevoid
putData(long offset, ByteBuffer buf)
Write entire buffer into volumevoid
putData(long offset, ByteBuffer[] bufs)
Write entire buffers into volumevoid
putData(long offset, ByteBuffer data, int size)
Write data from byteBuffer into volumevoid
putInt(long offset, int value)
Put integer value into volumevoid
putLong(long offset, long value)
Put long value into volumevoid
renameTo(String newName)
Rename db file to specified namevoid
reopen()
Reopen previously closed volumevoid
sync()
Call sync command to write all cached data
-
-
-
Field Detail
-
file
protected File file
-
raf
protected RandomAccessFile raf
-
readOnly
protected final boolean readOnly
-
fc
protected FileChannel fc
-
-
Constructor Detail
-
Volume
public Volume(File file, boolean readOnly)
Volume constructor, open or create volume file- Parameters:
file
- the file where volume should store (notnull
)readOnly
- open for read-onlytrue
flag (otherwise open in read-write mode)
-
-
Method Detail
-
renameTo
public void renameTo(String newName)
Rename db file to specified name- Parameters:
newName
- the new name (notnull
)
-
putData
public void putData(long offset, ByteBuffer data, int size)
Write data from byteBuffer into volume- Parameters:
offset
- the offset in volume to wheredata
- the buffer with data (reading from current bufer position) (notnull
)size
- the size of data to write
-
getData
public int getData(long offset, ByteBuffer bytes, int bytesPos, int size)
Read data from volume- Parameters:
offset
- the offset in volumebytes
- the buffer to store readed data (notnull
)bytesPos
- the offset in buffer to store datasize
- the size of data to read- Returns:
- the number of bytes read.
-
putData
public void putData(long offset, ByteBuffer buf)
Write entire buffer into volume- Parameters:
offset
- the offset in volumebuf
- buffer to write (notnull
)
-
putData
public void putData(long offset, ByteBuffer[] bufs)
Write entire buffers into volume- Parameters:
offset
- the offset in volumebufs
- the buffers to write (notnull
)
-
copyFile
public static void copyFile(File sourceFile, File destFile)
Copy file with all its contents- Parameters:
sourceFile
- the source file (notnull
)destFile
- the destination file (notnull
)
-
drop
public void drop()
Drop volume (close and delete from disc)
-
close
public void close()
Close volume
-
reopen
public void reopen()
Reopen previously closed volume
-
sync
public void sync()
Call sync command to write all cached data
-
isEmpty
public boolean isEmpty()
Test is volume empty (have zero size)- Returns:
true
if volume is emptyfalse
otherwise.
-
length
public long length()
Get length of volume- Returns:
- the volume length in bytes
-
getFile
public File getFile()
Get volume file- Returns:
- volume file
-
putLong
public void putLong(long offset, long value)
Put long value into volume- Parameters:
offset
- the offset in volume to writevalue
- the value to write
-
getLong
public long getLong(long offset)
Read long value from volume- Parameters:
offset
- the offset in volume to read from- Returns:
- readed value
-
putInt
public void putInt(long offset, int value)
Put integer value into volume- Parameters:
offset
- the offset in volume to writevalue
- the valut to write
-
getInt
public int getInt(long offset)
Read integer value from volume- Parameters:
offset
- the offset in volume to read from- Returns:
- readed value
-
putByte
public void putByte(long offset, byte value)
Put byte value into volume- Parameters:
offset
- the offset in volume to writevalue
- the value to write
-
getByte
public byte getByte(long offset)
Read byte value from volume- Parameters:
offset
- the offset in volume to read from- Returns:
- readed value
-
-