Class ZipDirectory
- java.lang.Object
-
- lumis.portal.serialization.persistency.zip.ZipDirectory
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,IDirectory
,IFSDirectory
public class ZipDirectory extends java.lang.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(java.io.File zipFile)
ZipDirectory(java.io.File zipFile, boolean createIfNotExist)
ZipDirectory(java.io.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(java.lang.String zipFilePath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
delete()
Delete the repository.boolean
exists(java.lang.String filePath)
Check the existence of a file.protected void
finalize()
java.lang.String
getDescription()
Generate a general description of the directory, used mainly to compose exception messages.java.lang.String
getDirectoryPath()
java.io.InputStream
getInputStream(java.lang.String filePath)
Get anInputStream
to a repository file.java.io.OutputStream
getOutputStream(java.lang.String filePath)
Get anOutputStream
to a repository file.
-
-
-
Constructor Detail
-
ZipDirectory
public ZipDirectory(java.lang.String zipFilePath) throws java.io.FileNotFoundException
- Parameters:
zipFilePath
- path to the zip file.- Throws:
java.io.FileNotFoundException
- if the zip file was not found.
-
ZipDirectory
public ZipDirectory(java.io.InputStream inputStream) throws java.io.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:
java.io.IOException
- Since:
- 8.0.0
-
ZipDirectory
public ZipDirectory(java.io.File zipFile) throws java.io.FileNotFoundException
- Parameters:
zipFile
-File
that wraps the zip file.- Throws:
java.io.FileNotFoundException
- if the zip file was not found.
-
ZipDirectory
public ZipDirectory(java.io.File zipFile, boolean createIfNotExist) throws java.io.FileNotFoundException, java.io.IOException
- Parameters:
zipFile
-File
that wraps the zip file.createIfNotExist
- if true, the zip file will be created if it does not exist.- Throws:
java.io.FileNotFoundException
- if the zip file was not found and createIfNotExist=false.java.io.IOException
-
-
Method Detail
-
exists
public boolean exists(java.lang.String filePath) throws java.io.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:
java.lang.IllegalStateException
- if this method is called in an already closed instance.java.io.IOException
- if an I/O error occurs.
-
getDescription
public java.lang.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 java.io.InputStream getInputStream(java.lang.String filePath) throws StreamStillOpenException, java.io.FileNotFoundException, java.io.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.java.lang.IllegalStateException
- if this method is called in an already closed instance.java.io.FileNotFoundException
- if no file was found in specified filePath.java.io.IOException
- if an I/O error occurs.
-
getOutputStream
public java.io.OutputStream getOutputStream(java.lang.String filePath) throws StreamStillOpenException, java.io.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.java.lang.IllegalStateException
- if this method is called in an already closed instance.java.io.IOException
- if an I/O error occurs.
-
close
public void close() throws java.io.IOException
In this implementation, this method MUST be called in order to persist new added files.
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
delete
public void delete() throws java.io.IOException
Description copied from interface:IDirectory
Delete the repository.- Specified by:
delete
in interfaceIDirectory
- Throws:
java.io.IOException
- if an I/O error occurs.
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
getDirectoryPath
public java.lang.String getDirectoryPath()
- Specified by:
getDirectoryPath
in interfaceIFSDirectory
-
-