public interface Storage
The storage uses an identifier to store, retrieve or remove an entry. An identifier is an unlimited-length sequence (greater than 0) of letters, digits and special characters, the first of which must be a letter. The "letters" include lowercase(a-z) and uppercase(A-Z) ASCII latin characters and ASCII underscore(_). The "digits" include the ASCII digits(0-9). The special characters include ASCII hyphen(-) and ASCII dot(.).
This API does not ensure that concurrent accesses on the same ID are thread-safe.
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.
|
OutputStream append(String id) throws IOException
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(…); }
id
- the ID of the stored entry.IOException
- if an I/O error occurs.IllegalArgumentException
- if the given ID is not a valid identifier.boolean exists(String id) throws IOException
id
- the ID to check.true
if the given ID exists, false
otherwiseIOException
- if an I/O error occurs.IllegalArgumentException
- if the given ID is not a valid identifier.String[] getIds() throws IOException
IOException
- if an I/O error occurs.long getSize(String id) throws IOException
id
- the ID of the entry.IOException
- if an I/O error occurs.IOException
- if there is no entry stored with the given ID.IllegalArgumentException
- if the given ID is not a valid identifier.@Nullable InputStream load(String id) throws IOException
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.
id
- the ID of the entry to be returned.null
.IOException
- if an I/O error occurs.IllegalArgumentException
- if the given ID is not a valid identifier.OutputStream modify(String id, int offset) throws IOException
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.
id
- the ID of the stored entry.offset
- the offset at which to write data.IOException
- if an I/O error occurs.IllegalArgumentException
- if the given ID is not a valid identifier or if the given offset is negative.void move(String sourceId, String destinationId) throws IOException
If an entry is already stored with the destination ID, it is overwritten.
This operation may block the current thread depending on the implementation.
sourceId
- the old ID of the entry.destinationId
- the new ID of the entry.IOException
- if an I/O error occurs.IOException
- if there is no entry stored with the source ID.IllegalArgumentException
- if one of the given IDs is not a valid identifier.void remove(String id) throws IOException
This operation may block the current thread depending on the implementation.
id
- the ID of the entry to remove.IOException
- if an I/O error occurs.IOException
- if there is no entry stored with the given ID.IllegalArgumentException
- if the given ID is not a valid identifier.OutputStream store(String id) throws IOException
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(…); }
id
- the ID of the stored entry.IOException
- if an I/O error occurs.IllegalArgumentException
- if the given ID is not a valid identifier.