Package org.eclipse.rdf4j.sail.nativerdf.datastore

## 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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `class` | `DataFile.DataIterator` | An iterator that iterates over the data that is stored in a data file.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DataFile​(File file)` |
    `DataFile​(File file, boolean forceSync)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `clear()` | Discards all stored data.
    `void` | `close()` | Closes the data file, releasing any file locks that it might have.
    `byte[]` | `getData​(long offset)` | Gets the data that is stored at the specified offset.
    `File` | `getFile()` |
    `DataFile.DataIterator` | `iterator()` | Gets an iterator that can be used to iterate over all stored data.
    `long` | `storeData​(byte[] data)` | Stores the specified data and returns the byte-offset at which it has been stored.
    `void` | `sync()` | Syncs any unstored data to the hash file.
    `void` | `sync​(boolean force)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DataFile

          public DataFile​(File file)
                   throws IOException

      Throws:
        `IOException`

    - #### DataFile

          public DataFile​(File file,
                          boolean forceSync)
                   throws IOException

      Throws:
        `IOException`

  - ### Method Detail

    - #### getFile

          public File getFile()

    - #### 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.

    - #### 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.