Constructor and Description |
---|
StorageHeap()
Creates a not persistent storage.
|
Modifier and Type | Method and Description |
---|---|
OutputStream |
append(String id)
Appends some data to an entry referenced with an ID.
|
boolean |
exists(String id)
Tests whether an entry exists for this ID.
|
String[] |
getIds()
Returns all IDs of the stored entries.
|
long |
getSize(String id)
Returns the size of the entry stored with an ID.
|
InputStream |
load(String id)
Loads the data stored with a specific ID or
null if there is none. |
OutputStream |
modify(String id,
int offset)
Modifies the entry that is referenced by an ID.
|
void |
move(String sourceId,
String destinationId)
Changes the ID of an entry.
|
void |
remove(String id)
Removes the entry stored with an ID.
|
OutputStream |
store(String id)
Stores data that will be referenced with an ID.
|
public OutputStream append(String id) throws IOException
Storage
If an entry is already stored with this ID, its existing data is not removed and the given data will be added to the existing entry. Otherwise, a new entry is created.
This operation may block the current thread depending on the implementation.
The returned output stream must be flushed or closed to ensure that the data is available. Example of usage:
try(OutputStream outputStream = append(id)) { outputStream.write(…); outputStream.write(…); }
append
in interface Storage
id
- the ID of the stored entry.IOException
- if an I/O error occurs.public boolean exists(String id) throws IOException
Storage
exists
in interface Storage
id
- the ID to check.true
if the given ID exists, false
otherwiseIOException
- if an I/O error occurs.public String[] getIds() throws IOException
Storage
getIds
in interface Storage
IOException
- if an I/O error occurs.public long getSize(String id) throws IOException
Storage
getSize
in interface Storage
id
- the ID of the entry.IOException
- if an I/O error occurs.@Nullable public InputStream load(String id) throws IOException
Storage
null
if there is none.
The returned input stream must be closed by the caller.
This operation may block the current thread depending on the implementation.
load
in interface Storage
id
- the ID of the entry to be returned.null
.IOException
- if an I/O error occurs.public OutputStream modify(String id, int offset) throws IOException
Storage
If an entry is already stored with this ID, its existing data is not removed and only the targeted bytes will be overwritten. Otherwise, a new entry is created.
This operation may block the current thread depending on the implementation.
The returned output stream must be flushed or closed to ensure that the data is available.
modify
in interface Storage
id
- the ID of the stored entry.offset
- the offset at which to write data.IOException
- if an I/O error occurs.public void move(String sourceId, String destinationId) throws IOException
Storage
If an entry is already stored with the destination ID, it is overwritten.
This operation may block the current thread depending on the implementation.
move
in interface Storage
sourceId
- the old ID of the entry.destinationId
- the new ID of the entry.IOException
- if an I/O error occurs.public void remove(String id) throws IOException
Storage
This operation may block the current thread depending on the implementation.
remove
in interface Storage
id
- the ID of the entry to remove.IOException
- if an I/O error occurs.public OutputStream store(String id) throws IOException
Storage
If an entry is already stored with this ID, its existing data is fully removed and replaced by the given data. Otherwise, a new entry is created.
This operation may block the current thread depending on the implementation.
The returned output stream must be flushed or closed to ensure that the data is available. Example of usage:
try(OutputStream outputStream = store(id)) { outputStream.write(…); outputStream.write(…); }
store
in interface Storage
id
- the ID of the stored entry.IOException
- if an I/O error occurs.