| Constructor and Description |
|---|
SandboxedStorage()
Creates a sandboxed storage on file system.
|
SandboxedStorage(String root)
Creates a storage on file system specifying the root folder where the root folder will be created.
|
| Modifier and Type | Method and Description |
|---|---|
OutputStream |
append(String s)
Appends some data to an entry referenced with an ID.
|
boolean |
exists(String s)
Tests whether an entry exists for this ID.
|
String[] |
getIds()
Returns all IDs of the stored entries.
|
String |
getRootFolder(Module module)
Gets the root folder of the storage service for a given module.
|
long |
getSize(String s)
Returns the size of the entry stored with an ID.
|
InputStream |
load(String s)
Loads the data stored with a specific ID or
null if there is none. |
OutputStream |
modify(String s,
int i)
Modifies the entry that is referenced by an ID.
|
void |
move(String s,
String s1)
Changes the ID of an entry.
|
void |
remove(String s)
Removes the entry stored with an ID.
|
OutputStream |
store(String s)
Stores data that will be referenced with an ID.
|
public SandboxedStorage()
throws IOException
The root folder is determined dynamically depending on the KF context. Each module has a different one.
IOException - if the root cannot be created.Kernel.getContextOwner(),
StorageFs()public SandboxedStorage(String root) throws IOException
The root folder is determined dynamically depending on the KF context. Each module has a different one.
root - the root folder.IllegalArgumentException - if the root already exists and is not a directory.IOException - if the root cannot be created.public OutputStream append(String s) throws IOException
StorageIf 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 Storages - the ID of the stored entry.IOException - if an I/O error occurs.public boolean exists(String s) throws IOException
Storageexists in interface Storages - the ID to check.true if the given ID exists, false otherwiseIOException - if an I/O error occurs.public String[] getIds() throws IOException
StoragegetIds in interface StorageIOException - if an I/O error occurs.public String getRootFolder(Module module)
module - the module.public long getSize(String s) throws IOException
StoragegetSize in interface Storages - the ID of the entry.IOException - if an I/O error occurs.public InputStream load(String s) throws IOException
Storagenull 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 Storages - the ID of the entry to be returned.null.IOException - if an I/O error occurs.public OutputStream modify(String s, int i) throws IOException
StorageIf 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 Storages - the ID of the stored entry.i - the offset at which to write data.IOException - if an I/O error occurs.public void move(String s, String s1) throws IOException
StorageIf 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 Storages - the old ID of the entry.s1 - the new ID of the entry.IOException - if an I/O error occurs.public void remove(String s) throws IOException
StorageThis operation may block the current thread depending on the implementation.
remove in interface Storages - the ID of the entry to remove.IOException - if an I/O error occurs.public OutputStream store(String s) throws IOException
StorageIf 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 Storages - the ID of the stored entry.IOException - if an I/O error occurs.