public interface FileStore extends Component
A FileStore
abstracts the way resource files are stored in the KnowledgeStore allowing
different implementations to be plugged in. A FileStore
stores a list of files each
identified by a filename, with no (visible) directory structure. Files can be listed (
list()
), written (write(String)
), read ( read(String)
) or deleted (
delete(String)
), but not modified after they are written the first time. Note that a
FileStore
obeys the general contract and lifecycle of Component
.
Modifier and Type | Method and Description |
---|---|
void |
delete(String filename)
Deletes a file on the
FileStore . |
Stream<String> |
list()
Lists all the files stored on the
FileStore . |
InputStream |
read(String filename)
Read a file stored on the
FileStore . |
OutputStream |
write(String filename)
Writes a new file to the
FileStore . |
InputStream read(String filename) throws FileMissingException, IOException
FileStore
. The method returns an InputStream
over
the content of the file, starting from its first byte. Sequential access and forward
seeking ( InputStream.skip(long)
) are supported. Note that multiple concurrent read
operations on the same file are allowed.filename
- the name of the fileInputStream
allowing access to the content of the fileFileMissingException
- in case no file exists for the name specified, resulting either from a caller
error or from an external modification (deletion) to the FileStore
IOException
- in case the file cannot be accessed for whatever reason, with no implication on
the fact that the file exists or does not exist (e.g., the whole
FileStore
may temporarily be not accessible)OutputStream write(String filename) throws FileExistsException, IOException
FileStore
. The method creates a file with the name
specified, and returns an OutputStream
that can be used to write the content of the
file. Writing is completed by closing that stream, which forces written data to be flushed
to disk; errors in writing the file may result in the stream being forcedly closed and a
truncated file to be written. The file being written may be listed by list()
(depending on the FileStore
implementation) but should not be accessed for read or
deletion until writing is completed; the consequences of doing so are not specified.filename
- the name of the fileOutputStream
where the content of the file can be written toFileExistsException
- in case a file with the same name already exists, resulting either from a
caller error or from an external modification (file creation) to the
FileStore
.IOException
- in case the file cannot be created for whatever reason, with no implication on
the fact that another file with the same name already existsvoid delete(String filename) throws FileMissingException, IOException
FileStore
. An exception is thrown if the file specified does
not exist. After the method returns, the file cannot be accessed anymore from
read(String)
or delete(String)
. Deleting a file being read is allowed and
eventually results in the deletion of the file; whether the concurrent read operation fails
or is permitted to complete is an implementation detail.filename
- the name of the fileFileMissingException
- in case the file specified does not exist, possibly because of an external
modification to the FileStore
IOException
- in case the file cannot be accessed for whatever reason, with no implication on
the fact that the file specified actually existsStream<String> list() throws IOException
FileStore
. The method returns a Stream
supporting streaming access to the names of the files stored in the FileStore
.
Concurrent modifications to the FileStore
(write(String)
,
delete(String)
) may be supported, depending on the implementation: in that case,
the stream may either reflect the status before or after the concurrent modification.FileStore
IOException
- in case of failure, for whatever reasonCopyright © 2015–2016 FBK-irst. All rights reserved.