org.entityfs.util.zip
Class ZipFiles

java.lang.Object
  extended by org.entityfs.util.zip.ZipFiles

public final class ZipFiles
extends Object

This is a utility class for working with Zip files.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-util

Method Summary
static void unzip(EFile f, DirectoryView dv, Filter<? super EntityView> ef)
          Extract the entities that pass the filter from the supplied Zip or Jar file into the directory.
static void unzip(ReadableFile f, DirectoryView dv)
          Unzip the supplied Zip or Jar file into the directory.
static void unzip(ReadableFile f, DirectoryView dv, boolean overwrite)
          Unzip the supplied Zip or Jar file into the directory.
static void unzip(ReadableFile f, DirectoryView dv, OverwriteStrategy overwriteStrategy)
           
static EFile zip(DirectoryView root, AbsoluteLocation zipRoot, DirectoryView target, String name)
          Create a new Zip file and put all its contents under the supplied absolute location in the Zip file.
static EFile zip(DirectoryView root, DirectoryView target, String name)
          Create a new Zip file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unzip

public static void unzip(ReadableFile f,
                         DirectoryView dv,
                         OverwriteStrategy overwriteStrategy)
                  throws EntityFoundException,
                         DirectoryNotEmptyException
Throws:
EntityFoundException
DirectoryNotEmptyException

unzip

public static void unzip(ReadableFile f,
                         DirectoryView dv,
                         boolean overwrite)
                  throws EntityFoundException,
                         DirectoryNotEmptyException
Unzip the supplied Zip or Jar file into the directory. The file will be locked for reading and the target directory (and subdirectories) will be locked for writing while this method is executing.

If overwrite is set to true, existing entities in the target directory will be overwritten with files from the Zip file if their names are the same. If the existing entity is a directory with some contents, it will be preserved and an DirectoryNotEmptyException is thrown instead.

Parameters:
f - The Zip file.
dv - The target directory.
overwrite - Should a file in the target directory with the same name as a file from the Zip archive be overwritten? A value of true means that the DoOverwriteAndLogWarning overwrite strategy is used, a value of false gives the DontOverwriteAndThrowException strategy.
Throws:
EntityFoundException - If a file that this method tries to create already exists and overwrite is set to false. When the exception is thrown, the target directory will contain the contents of the Zip file that was unzipped so far.
DirectoryNotEmptyException - If a file from the Zip archive has the same name as a non-empty directory in the target directory.
See Also:
unzip(EFile, DirectoryView, Filter), unzip(ReadableFile, DirectoryView, boolean)

unzip

public static void unzip(ReadableFile f,
                         DirectoryView dv)
                  throws EntityFoundException
Unzip the supplied Zip or Jar file into the directory. The file will be locked for reading and the target directory (and subdirectories) will be locked for writing while this method is executing.

Parameters:
f - The Zip file.
dv - The target directory.
Throws:
EntityFoundException - If a file that this method tries to create already exists. When the exception is thrown, the target directory will contain the contents of the Zip file that was unzipped so far.
See Also:
unzip(EFile, DirectoryView, Filter), unzip(ReadableFile, DirectoryView, boolean)

unzip

public static void unzip(EFile f,
                         DirectoryView dv,
                         Filter<? super EntityView> ef)
                  throws EntityFoundException
Extract the entities that pass the filter from the supplied Zip or Jar file into the directory. The file will be locked for reading and the target directory (and subdirectories) will be locked for writing while this method is executing.

Parameters:
f - The Zip file. This must be in a java.io.File backed file system.
dv - The target directory.
ef - The filter that the entities to extract must pass.
Throws:
EntityFoundException - If a file that this method tries to create already exists. When the exception is thrown, the target directory will contain the contents of the Zip file that was unzipped so far.
See Also:
unzip(ReadableFile, DirectoryView)

zip

public static EFile zip(DirectoryView root,
                        DirectoryView target,
                        String name)
                 throws EntityFoundException
Create a new Zip file. The contents of the root directory is added to the root directory of the Zip file.

This method uses the ZipCreator class. For more control over the Zip file contents, use the Zip builder from the At4J project instead.

Parameters:
root - The directory whose contents should be added to the Zip file. The directory itself is not added.
target - The target directory where the Zip file will be created.
name - The name of the created Zip file.
Returns:
The created Zip file.
Throws:
EntityFoundException - If the target file already exists.
Since:
1.1
See Also:
zip(DirectoryView, AbsoluteLocation, DirectoryView, String)

zip

public static EFile zip(DirectoryView root,
                        AbsoluteLocation zipRoot,
                        DirectoryView target,
                        String name)
                 throws EntityFoundException
Create a new Zip file and put all its contents under the supplied absolute location in the Zip file.

This method uses the ZipCreator class. For more control over the Zip file contents, use the Zip builder from the At4J project instead.

Parameters:
root - The directory whose contents should be added to the Zip file. The directory itself is not added.
zipRoot - The absolute location under which contents are added to the Zip file.
target - The target directory where the Zip file will be created.
name - The name of the created Zip file.
Returns:
The created Zip file.
Throws:
EntityFoundException - If the target file already exists.
Since:
1.1
See Also:
zip(DirectoryView, DirectoryView, String)