Class DataFile

java.lang.Object
org.eclipse.rdf4j.sail.nativerdf.datastore.DataFile
All Implemented Interfaces:
Closeable, AutoCloseable

public class DataFile extends Object implements Closeable
Class supplying access to a data file. A data file stores data sequentially. Each entry starts with the entry's length (4 bytes), followed by the data itself. File offsets are used to identify entries.
Author:
Arjohn Kampman
  • Field Details

    • LARGE_READ_THRESHOLD_PROPERTY

      public static final String LARGE_READ_THRESHOLD_PROPERTY
      See Also:
    • LARGE_READ_THRESHOLD

      public static final int LARGE_READ_THRESHOLD
  • Constructor Details

  • Method Details

    • getFile

      public File getFile()
    • getFileSize

      public long getFileSize() throws IOException
      Returns the current file size (after flushing any pending writes).
      Throws:
      IOException
    • tryRecoverBetweenOffsets

      public byte[] tryRecoverBetweenOffsets(long startOffset, long endOffset) throws IOException
      Attempts to recover data bytes between two known entry offsets when the length field at startOffset is corrupt (e.g., zero). This returns up to endOffset - startOffset - 4 bytes starting after the length field, capped to a reasonable maximum to avoid large allocations.
      Throws:
      IOException
    • storeData

      public long storeData(byte[] data) throws IOException
      Stores the specified data and returns the byte-offset at which it has been stored.
      Parameters:
      data - The data to store, must not be null.
      Returns:
      The byte-offset in the file at which the data was stored.
      Throws:
      IOException
    • getData

      public byte[] getData(long offset) throws IOException
      Gets the data that is stored at the specified offset.
      Parameters:
      offset - An offset in the data file, must be larger than 0.
      Returns:
      The data that was found on the specified offset.
      Throws:
      IOException - If an I/O error occurred.
    • getFreeMemory

      @InternalUseOnly public long getFreeMemory(Runtime rt)
    • clear

      public void clear() throws IOException
      Discards all stored data.
      Throws:
      IOException - If an I/O error occurred.
    • sync

      public void sync() throws IOException
      Syncs any unstored data to the hash file.
      Throws:
      IOException
    • sync

      public void sync(boolean force) throws IOException
      Throws:
      IOException
    • close

      public void close() throws IOException
      Closes the data file, releasing any file locks that it might have.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • iterator

      public DataFile.DataIterator iterator()
      Gets an iterator that can be used to iterate over all stored data.
      Returns:
      a DataIterator.