com.kuka.common
Class ZipUtil

java.lang.Object
  extended by com.kuka.common.ZipUtil

public final class ZipUtil
extends Object

Utility class for handling zip archives.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

Method Summary
static List<String> compareForAddedFiles(File fileBase, File fileComparison)
          Compares two zip files in order to find added files.
static List<String> compareForAddedFiles(String fileBasePath, String fileComparisonPath)
          Compares two zip files in order to find added files.
static List<String> compareForDeletedFiles(File fileBase, File fileComparison)
          Compares two zip files in order to find deleted files.
static List<String> compareForDeletedFiles(String fileBasePath, String fileComparisonPath)
          Compares two zip files in order to find deleted files.
static List<String> compareForSameFiles(File fileBase, File fileComparison)
          Compares two zip files in order to find files that are contained in both archives.
static void createZipFile(File root, File destination)
          Creates a zip file from the contents of a directory.
static void enumerate(URI zipURI, String itemId, File destinationDir, IFileVisitor visitor, IProgressListener listener)
          Extracts parts of or complete content of a given zip file to a given destination.
static void extractAll(File zipFile, File destinationDir)
          Extracts the whole ZIP file to the specified destination directory.
static File extractFile(File zipFile, String fileToExtract, File extractionPath, boolean extractFullPath)
          Extracts a single file from a zip archive.
static List<String> getAllFilenames(File zipFile)
          Query for all filenames of a given zip file.
static List<String> getAllFilenames(File zipFile, String subPath)
          Gets all file names under the specified subpath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractAll

public static void extractAll(File zipFile,
                              File destinationDir)
                       throws IOException
Extracts the whole ZIP file to the specified destination directory.

Parameters:
zipFile - ZIP file to extract.
destinationDir - destination directory where ZIP file should be extracted to
Throws:
IOException - if an I/O error has occurred

extractFile

public static File extractFile(File zipFile,
                               String fileToExtract,
                               File extractionPath,
                               boolean extractFullPath)
                        throws IOException
Extracts a single file from a zip archive.

Parameters:
zipFile - the zip archive containing the file.
fileToExtract - the file to extract (including the path within the zip archive).
extractionPath - the destination path (must be an existing directory).
extractFullPath - if true, the file is extracted with its full path within the zip archive. Otherwise only the file is extracted to the destination directory.
Returns:
the extracted file or null if the file to extract was not found within the zip archive.
Throws:
IOException - extracting file or opening zip archive fails.

getAllFilenames

public static List<String> getAllFilenames(File zipFile)
                                    throws IOException
Query for all filenames of a given zip file.

Parameters:
zipFile - file The zip file to be queried
Returns:
A list of filenames as strings
Throws:
IOException - If zip file could not be opened, an IOException is thrown

getAllFilenames

public static List<String> getAllFilenames(File zipFile,
                                           String subPath)
                                    throws IOException
Gets all file names under the specified subpath.

Parameters:
zipFile - file The zip file to be queried
subPath - sub path to search for files
Returns:
list with all files under the specified sub Path in the ZIP archive or an empty List if sub path not found or no files under the sub path.
Throws:
IOException - error opening or closing the zip file.

createZipFile

public static void createZipFile(File root,
                                 File destination)
                          throws IOException
Creates a zip file from the contents of a directory.

Parameters:
root - The root folder of the files and directories to put in the zip file.
destination - The destination file. Will be overwritten.
Throws:
IOException - Error during execution.

enumerate

public static void enumerate(URI zipURI,
                             String itemId,
                             File destinationDir,
                             IFileVisitor visitor,
                             IProgressListener listener)
                      throws IOException
Extracts parts of or complete content of a given zip file to a given destination.

Parameters:
zipURI - The location of the zip file.
itemId - The description of which part of the zip content should be extracted.
destinationDir - The location where the zip content should be extracted.
visitor - A instance of an object which will be called if the current item of the zip content should be extracted.
listener - A listener instance (optional). Will be called for each item that will be extracted.
Throws:
IOException - If the given zip URI is invalid.

compareForDeletedFiles

public static List<String> compareForDeletedFiles(String fileBasePath,
                                                  String fileComparisonPath)
                                           throws IOException
Compares two zip files in order to find deleted files. Deleted files are contained in the base zip file but not in the comparison zip file.

Parameters:
fileBasePath - the base zip file which is used as the reference for the comparison
fileComparisonPath - the zip file which is analyzed for deleted files
Returns:
the list of deleted files
Throws:
IOException - IO exception if the files to be compared cannot be found or opened

compareForDeletedFiles

public static List<String> compareForDeletedFiles(File fileBase,
                                                  File fileComparison)
                                           throws IOException
Compares two zip files in order to find deleted files. Deleted files are contained in the base zip file but not in the comparison zip file.

Parameters:
fileBase - the base zip file which is used as the reference for the comparison
fileComparison - the zip file which is analyzed for deleted files
Returns:
the list of deleted files
Throws:
IOException - IO exception if the files to be compared cannot be found or opened

compareForAddedFiles

public static List<String> compareForAddedFiles(String fileBasePath,
                                                String fileComparisonPath)
                                         throws IOException
Compares two zip files in order to find added files. Added files are contained in the comparison zip file but not in the base zip file.

Parameters:
fileBasePath - the base zip file which is used as the reference for the comparison
fileComparisonPath - the zip file which is analyzed for added files
Returns:
the list of added files
Throws:
IOException - IO exception if the files to be compared cannot be found or opened

compareForAddedFiles

public static List<String> compareForAddedFiles(File fileBase,
                                                File fileComparison)
                                         throws IOException
Compares two zip files in order to find added files. Added files are contained in the comparison zip file but not in the base zip file.

Parameters:
fileBase - the base zip file which is used as the reference for the comparison
fileComparison - the zip file which is analyzed for added files
Returns:
the list of added files
Throws:
IOException - IO exception if the files to be compared cannot be found or opened

compareForSameFiles

public static List<String> compareForSameFiles(File fileBase,
                                               File fileComparison)
                                        throws IOException
Compares two zip files in order to find files that are contained in both archives.

Parameters:
fileBase - the base zip file which is used as the reference for the comparison
fileComparison - the zip file which is analyzed for same files
Returns:
the list of same files
Throws:
IOException - IO exception if the files to be compared cannot be found or opened


Copyright © 2019. All rights reserved.