net.simplace.util.service.ZIPHelper
All the zip operations are handled.
public final class ZIPHelper {
// Class Methods public static void
createZIPWithPathEntries(File aDirectory, File aZipFile)
throws ZipException;
Packs the given directory into a new zip file with the given name
public static void
createZIPWithPathEntries(Collection aFilesCollection,
File aDestinationFile, String aParentStartPath) throws ZipException;
Creates a zip file out of a collection of files. The zip file created will have the path information of each file
so that when it is unzipped then it is copied into the specific directory format. The relative path name is also
given as parameter. Also fecilitates with the feature of adding empty directory entries. (i.e if the list of files
contains a directory then it is added as a directory zip entry.) *
- aFilesCollection
- aDestinationFile
- aParentStartPath
public static void
unZIPWithPath(File aSourceZipFile, String aDestinationDir)
throws ZipException;
Unzips a zip file to the given directory structure as how the zipentry specifies. If a directory zip entry exists
then a empty directory with the entry name is created.
- aSourceZipFile
- aDestinationDir
public static final boolean
packAndDeleteDirContents(File aZipFile, File
aDir, String aExtension, long aOlderThanMillis);
Deletes all the files in a directory excluding the subdirectories files, if the given file is a directory but does
not delete the directory itself. Before it Zips the given Files to another place.
- aZipFile
- aDir
- aExtension
- aOlderThanMillis
returns success
public static void
createZIP(Collection aFilesCollection, File
aDestinationFile) throws ZipException;
Creates a zip file out of a collection of files.
- aFilesCollection
- aDestinationFile
public static void
createZIP(String aFileName, InputStream aInputStream,
File aDestinationFile) throws ZipException;
Creates a zip file out of a InputStream.
- aFileName
- aInputStream
- aDestinationFile
public static void
addToZIP(Collection aFilesCollection, File aSourceZipFile,
File aDestinationZipFile) throws ZipException;
Add a file(s) to the zip file from a collection of files.
- aFilesCollection
- aSourceZipFile
- aDestinationZipFile
public static void
addToZIP(File aFileToAdd, File aSourceZipFile, File
aDestinationZipFile) throws ZipException;
Add a file(s) to the zip file from a collection of files.
- aFileToAdd
- aSourceZipFile
- aDestinationZipFile
public static File
createZIP(Collection aZipEntriesColl, File aSourceZipFile,
File aDestinationZipFile) throws ZipException;
Generates a new Zip file out of an existing zip file with specific zip entries only.
- aZipEntriesColl
- aSourceZipFile
- aDestinationZipFile
returns a new Zip file
public static List
unZIP(File aSourceZipFile, String aDestinationDir)
throws ZipException;
Unzips a zip file to the given directory and returns a map of unzipped-files
- aSourceZipFile
- aDestinationDir
returns a list of unzipped-files
public static List
unZIP(File aSourceZipFile, String aDestinationDir,
boolean aReplacePercentInPath) throws ZipException;
Unzips a zip file to the given directory and returns a map of unzipped-files
- aSourceZipFile
- aDestinationDir
- aReplacePercentInPath
returns a list of unzipped-files
public static List
unZIP(File aSourceZipFile, String aSubPath, String
aDestinationDir) throws ZipException;
Unzips a zip file to the given directory and returns a map of unzipped-files. Will only unzip files with the given
subPath.
- aSourceZipFile
- aSubPath
- aDestinationDir
returns a list of unzipped-files
public static List
unZIP(File aSourceZipFile, String aSubPath, String
aDestinationDir, boolean aReplacePercentInPath) throws ZipException;
Unzips a zip file to the given directory and returns a map of unzipped-files. Will only unzip files with the given
subPath.
- aSourceZipFile
- aSubPath
- aDestinationDir
- aReplacePercentInPath
returns a list of unzipped-files
public static Collection
getZIPEntries(File aSourceZipFile)
throws ZipException;
Extracts the entries of the given zip-file.
returns Collection of the entries of the given zip-file
public static Collection
getZIPEntriesHavingPathName(File aSourceZipFile,
String aName) throws ZipException;
Returns the entries of a zip file which contains the given name.
returns the entries of a zip file which contains the given name
public static Collection
getZIPEntriesWithoutPathName(File aSourceZipFile,
String aName) throws ZipException;
Returns the entries of a zip file without the given name.
returns the entries of a zip file without the given name
public static ZipEntry
getZIPEntry(File aSourceZipFile, String aFileName)
throws ZipException;
Get the entries of a zip file
returns the entries of a zip file
public static ZipEntry
getZIPEntryExcludingPath(File aSourceZipFile, String
aFileName) throws ZipException;
Returs the zip entry of the given file name with out the path info.
returns the zip entry of the given file name with out the path info
public static void
removeZipEntry(List aFilenameList, File aSourceZipFile,
File aDestinationZipFile) throws ZipException;
Add a file(s) to the zip file from a collection of files.
- aFilenameList
- aSourceZipFile
- aDestinationZipFile
public static void
removeZipEntry(String aFilename, File aSourceZipFile,
File aDestinationZipFile) throws ZipException;
Add a file(s) to the zip file from a collection of files.
- aFilename
- aSourceZipFile
- aDestinationZipFile
public static boolean
readZIPEntry(File aSourceZipFile, File
aDestinationFile, String aFileName) throws ZipException, IOException;
This method reads a given file out of a ZipFile and writes it to the destination file.
- aSourceZipFile
- aDestinationFile
- aFileName
returns success
public static char
getFileSeparator(File aZipArchive);
Parses the Entries of the given Zip archive and looks for the file separator character, if it is a directory. This
method is useful as you don't know if the ZipArchive was packed on a Linux or on a Windows system. Both operating
systems use different file separators when creating a zip archive. if it should be unzipped on the other OS, this
might lead to errors.
returns file separator
public static void
flattenZipArchive(File aSourceFile, File aDestinationFile)
throws ZipException;
Iterates all ZipEntries in the source file and moves them into a new ZipArchive aDestinationFile. Only files are
moved. Directories are not moved. Files are written to the new archive without path entries.
- aSourceFile
- aDestinationFile
}