org.openrdf.sail.nativerdf.datastore
Class DataFile

java.lang.Object
  extended by org.openrdf.sail.nativerdf.datastore.DataFile

public class DataFile
extends Object

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
 class DataFile.DataIterator
          An iterator that iterates over the data that is stored in a data file.
 
Constructor Summary
DataFile(File file)
           
DataFile(File file, boolean forceSync)
           
 
Method Summary
 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.
 
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

close

public void close()
           throws IOException
Closes the data file, releasing any file locks that it might have.

Throws:
IOException

iterator

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

Returns:
a DataIterator.


Copyright © 2001-2007 Aduna. All Rights Reserved.