Class 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
    • 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.
      • iterator

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