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 classDataFile.DataIteratorAn iterator that iterates over the data that is stored in a data file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Discards all stored data.voidclose()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.FilegetFile()DataFile.DataIteratoriterator()Gets an iterator that can be used to iterate over all stored data.longstoreData(byte[] data)Stores the specified data and returns the byte-offset at which it has been stored.voidsync()Syncs any unstored data to the hash file.voidsync(boolean force)
-
-
-
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 IOExceptionStores 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 IOExceptionGets 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 IOExceptionDiscards all stored data.- Throws:
IOException- If an I/O error occurred.
-
sync
public void sync() throws IOExceptionSyncs any unstored data to the hash file.- Throws:
IOException
-
sync
public void sync(boolean force) throws IOException- Throws:
IOException
-
close
public void close() throws IOExceptionCloses the data file, releasing any file locks that it might have.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
iterator
public DataFile.DataIterator iterator()
Gets an iterator that can be used to iterate over all stored data.- Returns:
- a DataIterator.
-
-