Class ZipDirectory
- java.lang.Object
-
- lumis.portal.serialization.persistency.zip.ZipDirectory
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,IDirectory
,IFSDirectory
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 anStreamStillOpenException
.- Since:
- 4.0.10
- Version:
- $Revision: 22305 $ $Date: 2019-01-24 14:44:48 -0200 (Thu, 24 Jan 2019) $
-
-
Constructor Summary
Constructors Constructor 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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 anInputStream
to a repository file.OutputStream
getOutputStream(String filePath)
Get anOutputStream
to a repository file.
-
-
-
Constructor Detail
-
ZipDirectory
public ZipDirectory(String zipFilePath) throws FileNotFoundException
- Parameters:
zipFilePath
- path to the zip file.- Throws:
FileNotFoundException
- if the zip file was not found.
-
ZipDirectory
public ZipDirectory(InputStream inputStream) throws IOException
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.- Parameters:
inputStream
- the input stream.- Throws:
IOException
- Since:
- 8.0.0
-
ZipDirectory
public ZipDirectory(File zipFile) throws FileNotFoundException
- Parameters:
zipFile
-File
that wraps the zip file.- Throws:
FileNotFoundException
- if the zip file was not found.
-
ZipDirectory
public ZipDirectory(File zipFile, boolean createIfNotExist) throws FileNotFoundException, IOException
- Parameters:
zipFile
-File
that wraps the zip file.createIfNotExist
- if true, the zip file will be created if it does not exist.- Throws:
FileNotFoundException
- if the zip file was not found and createIfNotExist=false.IOException
-
-
Method Detail
-
exists
public boolean exists(String filePath) throws IOException
Check the existence of a file.- Specified by:
exists
in interfaceIDirectory
- Parameters:
filePath
- path to the file to be checked.- Returns:
- true, if the specified file exists.
- Throws:
IllegalStateException
- if this method is called in an already closed instance.IOException
- if an I/O error occurs.
-
getDescription
public String getDescription()
Description copied from interface:IDirectory
Generate a general description of the directory, used mainly to compose exception messages.- Specified by:
getDescription
in interfaceIDirectory
- Returns:
- directory description.
-
getInputStream
public InputStream getInputStream(String filePath) throws StreamStillOpenException, FileNotFoundException, IOException
Get anInputStream
to a repository file.This implementation does not allow more than one stream open at a time.
- Specified by:
getInputStream
in interfaceIDirectory
- Parameters:
filePath
- path to the file.- Returns:
InputStream
to file found in specified filePath.- Throws:
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.
-
getOutputStream
public OutputStream getOutputStream(String filePath) throws StreamStillOpenException, IOException
Get anOutputStream
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 methodclose()
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.- Specified by:
getOutputStream
in interfaceIDirectory
- Parameters:
filePath
- path to the file.- Returns:
OutputStream
to the new file- Throws:
StreamStillOpenException
- 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.
-
close
public void close() throws IOException
In this implementation, this method MUST be called in order to persist new added files.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
delete
public void delete() throws IOException
Description copied from interface:IDirectory
Delete the repository.- Specified by:
delete
in interfaceIDirectory
- Throws:
IOException
- if an I/O error occurs.
-
finalize
protected void finalize() throws Throwable
-
getDirectoryPath
public String getDirectoryPath()
- Specified by:
getDirectoryPath
in interfaceIFSDirectory
-
-