T - The type of the stored objectpublic class Storage<T extends Storable> extends Object implements Closeable
Storables. The storage persists the objects to a data
file, using a second index file to keep track of allocated blocks.| Constructor and Description |
|---|
Storage(Factory<T> factory,
File directory,
String name)
Creates a new storage with a default block size of 512 bytes.
|
Storage(int blockSize,
Factory<T> factory,
File directory,
String name)
Creates a new storage.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T storable)
Adds a storable to this storage.
|
void |
close() |
void |
compact()
Compacts the directory.
|
Allocation |
getAllocation(int directoryIndex)
Returns the allocation at the given directory index.
|
int |
getDirectorySize()
Returns the size of the directory.
|
T |
load(long id)
Loads a storable.
|
void |
open()
Opens this storage.
|
void |
remove(long id)
Removes the storable with the given ID.
|
void |
remove(T storable)
Removes a storable.
|
int |
size()
Returns the number of storables in this storage.
|
public Storage(Factory<T> factory, File directory, String name)
factory - The factory that creates the objectsdirectory - The directory to store the files inname - The base name of the filespublic void open()
throws StorageException
StorageException - if the storage can not be openedpublic void add(T storable) throws StorageException
storable - The storable to storeStorageException - if a store error occurspublic int size()
public T load(long id) throws StorageException
id - The ID of the storable to loadStorageException - if the Storable could not be loadedpublic int getDirectorySize()
size() because it also includes empty directory entries!public Allocation getAllocation(int directoryIndex)
directoryIndex - The directory indexnull if there is no
allocation at the given indexpublic void remove(T storable) throws StorageException
storable - The storable to removeStorageException - if the index file can not be written topublic void remove(long id)
throws StorageException
id - The ID of the storable to removeStorageException - if the index file can not be written topublic void close()
close in interface Closeableclose in interface AutoCloseablepublic void compact()
throws StorageException
StorageException - if the index file can not be compactedCopyright © 2026. All rights reserved.