Class Volume


  • public class Volume
    extends Object
    Wrapper around file with databse
    • Constructor Detail

      • Volume

        public Volume​(File file,
                      boolean readOnly)
        Volume constructor, open or create volume file
        Parameters:
        file - the file where volume should store (not null)
        readOnly - open for read-only true 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 (not null)
      • putData

        public void putData​(long offset,
                            ByteBuffer data,
                            int size)
        Write data from byteBuffer into volume
        Parameters:
        offset - the offset in volume to where
        data - the buffer with data (reading from current bufer position) (not null)
        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 volume
        bytes - the buffer to store readed data (not null)
        bytesPos - the offset in buffer to store data
        size - 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 volume
        buf - buffer to write (not null)
      • putData

        public void putData​(long offset,
                            ByteBuffer[] bufs)
        Write entire buffers into volume
        Parameters:
        offset - the offset in volume
        bufs - the buffers to write (not null)
      • copyFile

        public static void copyFile​(File sourceFile,
                                    File destFile)
        Copy file with all its contents
        Parameters:
        sourceFile - the source file (not null)
        destFile - the destination file (not null)
      • 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 empty false 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 write
        value - 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 write
        value - 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 write
        value - 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