Class FileDataStore
- java.lang.Object
-
- eu.svjatoslav.sixth.data.store.file.FileDataStore
-
-
Constructor Summary
Constructors Constructor Description FileDataStore(File backingFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close datastore.int
createRecord(byte[] value)
Create new record and set its initial contents.void
deleteRecord(int id)
Delete record identified by given ID.long
getDefragmentationStartAddress(int allowedFragmentationPercent, List<eu.svjatoslav.sixth.data.store.file.EntryRecord> allEntryRecords)
void
increaseEntriesTable()
void
initializeFromExistingFile(File backingFile)
void
initializeNewFile(File backingFile)
int
readInt(long position)
long
readLong(long position)
byte[]
readRecord(int id)
Read entire record into byte array.long
relocateEntry(eu.svjatoslav.sixth.data.store.file.EntryRecord record, long newLocation)
void
updateRecord(int id, byte[] value)
Update record with new value.void
vacuum(int allowedFragmentationPercent)
Defragment empty space.void
writeInt(long position, int value)
void
writeLong(long position, long value)
-
-
-
Constructor Detail
-
FileDataStore
public FileDataStore(File backingFile) throws IOException
- Throws:
IOException
-
-
Method Detail
-
close
public void close() throws IOException
Description copied from interface:DataStore
Close datastore.- Specified by:
close
in interfaceDataStore
- Throws:
IOException
-
createRecord
public int createRecord(byte[] value) throws IOException
Description copied from interface:DataStore
Create new record and set its initial contents.- Specified by:
createRecord
in interfaceDataStore
- Throws:
IOException
-
deleteRecord
public void deleteRecord(int id) throws IOException
Description copied from interface:DataStore
Delete record identified by given ID. DataStore will mark given ID as unused, and could reuse this ID later for another newly created record.- Specified by:
deleteRecord
in interfaceDataStore
- Throws:
IOException
-
getDefragmentationStartAddress
public long getDefragmentationStartAddress(int allowedFragmentationPercent, List<eu.svjatoslav.sixth.data.store.file.EntryRecord> allEntryRecords)
-
increaseEntriesTable
public void increaseEntriesTable() throws IOException
- Throws:
IOException
-
initializeFromExistingFile
public void initializeFromExistingFile(File backingFile) throws IOException
- Throws:
IOException
-
initializeNewFile
public void initializeNewFile(File backingFile) throws IOException
- Throws:
IOException
-
readInt
public int readInt(long position) throws IOException
- Throws:
IOException
-
readLong
public long readLong(long position) throws IOException
- Throws:
IOException
-
readRecord
public byte[] readRecord(int id) throws IOException
Description copied from interface:DataStore
Read entire record into byte array.- Specified by:
readRecord
in interfaceDataStore
- Throws:
IOException
-
relocateEntry
public long relocateEntry(eu.svjatoslav.sixth.data.store.file.EntryRecord record, long newLocation) throws IOException
- Throws:
IOException
-
updateRecord
public void updateRecord(int id, byte[] value) throws IOException
Description copied from interface:DataStore
Update record with new value.- Specified by:
updateRecord
in interfaceDataStore
- Throws:
IOException
-
vacuum
public void vacuum(int allowedFragmentationPercent) throws IOException
Defragment empty space.- Parameters:
allowedFragmentationPercent
- allowed maximum percentage of free space, relative to total used space.- Throws:
IOException
-
writeInt
public void writeInt(long position, int value) throws IOException
- Throws:
IOException
-
writeLong
public void writeLong(long position, long value) throws IOException
- Throws:
IOException
-
-