## org.h2.mvstore
Class FileStore

    java.lang.Object
      org.h2.mvstore.FileStore

Direct Known Subclasses:
  OffHeapStore

    public class FileStore

extends java.lang.Object

The default storage mechanism of the MVStore. This implementation persists data to a file. The file store is responsible to persist data and for free space management.

Field Summary
`protected java.nio.channels.FileChannel` `encryptedFile` The encrypted file (if encryption is used).
`protected java.nio.channels.FileChannel` `file` The file.
`protected java.nio.channels.FileLock` `fileLock` The file lock.
`protected java.lang.String` `fileName` The file name.
`protected long` `fileSize` The file size (cached).
`protected FreeSpaceBitSet` `freeSpace` The free spaces between the chunks.
`protected long` `readCount` The number of read operations.
`protected boolean` `readOnly` Whether this store is read-only.
`protected long` `writeCount` The number of write operations.

Constructor Summary
`FileStore()`

Method Summary
`long` `allocate(int length)` Allocate a number of blocks and mark them as used.
`void` `clear()` Mark the file as empty.
`void` `close()` Close this store.
`void` `free(long pos, int length)` Mark the space as free.
`int` `getDefaultRetentionTime()` Get the default retention time for this store in milliseconds.
`java.nio.channels.FileChannel` `getEncryptedFile()` Get the encrypted file instance, if encryption is used.
`java.nio.channels.FileChannel` `getFile()` Get the file instance in use.
`int` `getFillRate()`
`long` `getFirstFree()`
`long` `getReadCount()` Get the number of read operations since this store was opened.
`long` `getWriteCount()` Get the number of write operations since this store was opened.
`boolean` `isReadOnly()`
`void` `markUsed(long pos, int length)` Mark the space as in use.
`void` `open(java.lang.String fileName, boolean readOnly, char[] encryptionKey)` Try to open the file.
`java.nio.ByteBuffer` `readFully(long pos, int len)` Read from the file.
`long` `size()` Get the file size.
`void` `sync()` Flush all changes.
`java.lang.String` `toString()`
`void` `truncate(long size)` Truncate the file.
`void` `writeFully(long pos, java.nio.ByteBuffer src)` Write to the file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### readCount

    protected long readCount

  The number of read operations.

### writeCount

    protected long writeCount

  The number of write operations.

### freeSpace

    protected final FreeSpaceBitSet freeSpace

  The free spaces between the chunks. The first block to use is block 2 (the first two blocks are the store header).

### fileName

    protected java.lang.String fileName

  The file name.

### readOnly

    protected boolean readOnly

  Whether this store is read-only.

### fileSize

    protected long fileSize

  The file size (cached).

### file

    protected java.nio.channels.FileChannel file

  The file.

### encryptedFile

    protected java.nio.channels.FileChannel encryptedFile

  The encrypted file (if encryption is used).

### fileLock

    protected java.nio.channels.FileLock fileLock

  The file lock.

Constructor Detail

### FileStore

    public FileStore()

Method Detail

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### readFully

    public java.nio.ByteBuffer readFully(long pos,
                                         int len)

  Read from the file.

  Parameters:
    `pos` - the write position
    `len` - the number of bytes to read
  Returns:
    the byte buffer

### writeFully

    public void writeFully(long pos,
                           java.nio.ByteBuffer src)

  Write to the file.

  Parameters:
    `pos` - the write position
    `src` - the source buffer

### open

    public void open(java.lang.String fileName,
                     boolean readOnly,
                     char[] encryptionKey)

  Try to open the file.

  Parameters:
    `fileName` - the file name
    `readOnly` - whether the file should only be opened in read-only mode, even if the file is writable
    `encryptionKey` - the encryption key, or null if encryption is not used

### close

    public void close()

  Close this store.

### sync

    public void sync()

  Flush all changes.

### size

    public long size()

  Get the file size.

  Returns:
    the file size

### truncate

    public void truncate(long size)

  Truncate the file.

  Parameters:
    `size` - the new file size

### getFile

    public java.nio.channels.FileChannel getFile()

  Get the file instance in use.

  The application may read from the file (for example for online backup), but not write to it or truncate it.

  Returns:
    the file

### getEncryptedFile

    public java.nio.channels.FileChannel getEncryptedFile()

  Get the encrypted file instance, if encryption is used.

  The application may read from the file (for example for online backup), but not write to it or truncate it.

  Returns:
    the encrypted file, or null if encryption is not used

### getWriteCount

    public long getWriteCount()

  Get the number of write operations since this store was opened. For file based stores, this is the number of file write operations.

  Returns:
    the number of write operations

### getReadCount

    public long getReadCount()

  Get the number of read operations since this store was opened. For file based stores, this is the number of file read operations.

  Returns:
    the number of read operations

### isReadOnly

    public boolean isReadOnly()

### getDefaultRetentionTime

    public int getDefaultRetentionTime()

  Get the default retention time for this store in milliseconds.

  Returns:
    the retention time

### markUsed

    public void markUsed(long pos,
                         int length)

  Mark the space as in use.

  Parameters:
    `pos` - the position in bytes
    `length` - the number of bytes

### allocate

    public long allocate(int length)

  Allocate a number of blocks and mark them as used.

  Parameters:
    `length` - the number of bytes to allocate
  Returns:
    the start position in bytes

### free

    public void free(long pos,
                     int length)

  Mark the space as free.

  Parameters:
    `pos` - the position in bytes
    `length` - the number of bytes

### getFillRate

    public int getFillRate()

### getFirstFree

    public long getFirstFree()

### clear

    public void clear()

  Mark the file as empty.