public class ZipDirectory extends Object implements IFSDirectory
IDirectory
implementation that uses a zip file as the concrete repository.
This implementation allows only one open stream at a time. Tries to get some input or output stream when another stream was got and not closed yet will raise an StreamStillOpenException
.Constructor and Description |
---|
ZipDirectory(File zipFile) |
ZipDirectory(File zipFile,
boolean createIfNotExist) |
ZipDirectory(InputStream inputStream)
Creates a new ZipDirectory from the given stream.
The stream will be consumed but will not be closed. The stream may be closed after this constructor is called. |
ZipDirectory(String zipFilePath) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
delete()
Delete the repository.
|
boolean |
exists(String filePath)
Check the existence of a file.
|
protected void |
finalize() |
String |
getDescription()
Generate a general description of the directory, used mainly to compose exception messages.
|
String |
getDirectoryPath() |
InputStream |
getInputStream(String filePath)
Get an
InputStream to a repository file. |
OutputStream |
getOutputStream(String filePath)
Get an
OutputStream to a repository file. |
public ZipDirectory(String zipFilePath) throws FileNotFoundException
zipFilePath
- path to the zip file.FileNotFoundException
- if the zip file was not found.public ZipDirectory(InputStream inputStream) throws IOException
inputStream
- the input stream.IOException
public ZipDirectory(File zipFile) throws FileNotFoundException
zipFile
- File
that wraps the zip file.FileNotFoundException
- if the zip file was not found.public ZipDirectory(File zipFile, boolean createIfNotExist) throws FileNotFoundException, IOException
zipFile
- File
that wraps the zip file.createIfNotExist
- if true, the zip file will be created if it does not exist.FileNotFoundException
- if the zip file was not found and createIfNotExist=false.IOException
public boolean exists(String filePath) throws IOException
exists
in interface IDirectory
filePath
- path to the file to be checked.IllegalStateException
- if this method is called in an already closed instance.IOException
- if an I/O error occurs.public String getDescription()
IDirectory
getDescription
in interface IDirectory
public InputStream getInputStream(String filePath) throws StreamStillOpenException, FileNotFoundException, IOException
InputStream
to a repository file.
This implementation does not allow more than one stream open at a time.
getInputStream
in interface IDirectory
filePath
- path to the file.InputStream
to file found in specified filePath.StreamStillOpenException
- if there is another stream that was gotten and not closed yet.IllegalStateException
- if this method is called in an already closed instance.FileNotFoundException
- if no file was found in specified filePath.IOException
- if an I/O error occurs.public OutputStream getOutputStream(String filePath) throws StreamStillOpenException, IOException
OutputStream
to a repository file.
Due to an output optimization, this implementation does not persist the new files just after closing the OutputStream
. To commit the persistence, the method close()
must be called.
This implementation does not allow more than one stream open at a time.
If the file already exists, an IOException
will be thrown.
getOutputStream
in interface IDirectory
filePath
- path to the file.OutputStream
to the new fileStreamStillOpenException
- if there is another stream that was gotten and not closed yet.IllegalStateException
- if this method is called in an already closed instance.IOException
- if an I/O error occurs.public void close() throws IOException
In this implementation, this method MUST be called in order to persist new added files.
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void delete() throws IOException
IDirectory
delete
in interface IDirectory
IOException
- if an I/O error occurs.protected void finalize() throws Throwable
public String getDirectoryPath()
getDirectoryPath
in interface IFSDirectory
LumisXP 12.1.0.191010 - Copyright © 2006–2019 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.