public final class GzippedFileStore extends ForwardingFileStore
FileStore
decorator that GZIPs all the compressible files written to it.
A GzippedFileStore
intercepts reads and writes to an underlying FileStore
,
respectively applying GZIP compression and decompression to stored files in case they are
compressible. Compression level and size of buffer used for compression / decompression can be
configured by the user. Whether a file can be compressed is detected starting from its
extension and the matching Internet MIME type using the facilities of Data
. In case
compression is applied, the name of the stored file is changed adding a .gz
suffix.
Constructor and Description |
---|
GzippedFileStore(FileStore delegate)
Creates a new instance wrapping the
FileStore supplied and using the default
compression level and buffer size. |
GzippedFileStore(FileStore delegate,
Integer compressionLevel,
Integer bufferSize,
Boolean forceCompression)
Creates a new instance wrapping the
FileStore supplied and using the specified
compression level. |
Modifier and Type | Method and Description |
---|---|
protected FileStore |
delegate() |
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 . |
close, init
toString
public GzippedFileStore(FileStore delegate)
FileStore
supplied and using the default
compression level and buffer size.delegate
- the wrapped FileStore
#GzippedFileStore(FileStore, Integer, Integer)
public GzippedFileStore(FileStore delegate, @Nullable Integer compressionLevel, @Nullable Integer bufferSize, @Nullable Boolean forceCompression)
FileStore
supplied and using the specified
compression level.delegate
- the wrapped FileStore
, not nullcompressionLevel
- the desired compression level for compressible files, on a 0-9 scale (from no
compression to best compression) or -1 for default compression; if null defaults
to -1bufferSize
- the size of the buffer used by the GZIP inflaters / deflaters; if null defaults
to 512forceCompression
- if true, supplied files are always compressed independently of their (detected)
MIME type; if null defaults to falseprotected FileStore delegate()
delegate
in class ForwardingFileStore
public InputStream read(String filename) throws FileMissingException, IOException
FileStore
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.read
in interface FileStore
read
in class ForwardingFileStore
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)public OutputStream write(String filename) throws FileExistsException, IOException
FileStore
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 FileStore.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.write
in interface FileStore
write
in class ForwardingFileStore
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 existspublic void delete(String filename) throws FileMissingException, IOException
FileStore
FileStore
. An exception is thrown if the file specified does
not exist. After the method returns, the file cannot be accessed anymore from
FileStore.read(String)
or FileStore.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.delete
in interface FileStore
delete
in class ForwardingFileStore
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 existspublic Stream<String> list() throws IOException
FileStore
FileStore
. The method returns a Stream
supporting streaming access to the names of the files stored in the FileStore
.
Concurrent modifications to the FileStore
(FileStore.write(String)
,
FileStore.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.list
in interface FileStore
list
in class ForwardingFileStore
FileStore
IOException
- in case of failure, for whatever reasonCopyright © 2015–2016 FBK-irst. All rights reserved.