eu.planets_project.services.utils
Class ZipUtils

java.lang.Object
  extended by eu.planets_project.services.utils.ZipUtils

public class ZipUtils
extends Object


Constructor Summary
ZipUtils()
           
 
Method Summary
static List<File> checkAndUnzipTo(File zipFile, File destFolder, Checksum checksum)
          Unzips a zip file and writes the content to destFolder, checking if the checksum is correct.
static File createZip(File srcFolder, File destFolder, String zipName, boolean compress)
          Creates a Zip64File zip file.
static ZipResult createZipAndCheck(File srcFolder, File destFolder, String zipName, boolean compress)
          Creates a Zip64File containing all the files in srcFolder and write it to destFolder using the passed zipName.
static String[] getAllFragments(File zip)
          A convenience method.
static File getFileFrom(File zip, String targetPathInZipfile, File destFolder)
          Extracts a file specified by targetPathInZipfile from the passed zip and writes it to destFolder.
static File insertFileInto(File zipFile, File toInsert, String targetPath)
          Inserts a file into a given zip at a location specified by targetPath.
static boolean isZipFile(File file)
           
static List<String> listZipEntries(File zip)
          Lists all entries in this zip file.
static File removeFileFrom(File zipFile, String fileToRemove)
          Removes the file 'fileToRemove' from zipFile.
static List<File> unzipTo(File zipFile, File destFolder)
          Unzips a zip file and writes the contained files to destFolder.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipUtils

public ZipUtils()
Method Detail

createZip

public static File createZip(File srcFolder,
                             File destFolder,
                             String zipName,
                             boolean compress)
Creates a Zip64File zip file.

Parameters:
srcFolder - the folder containing the files to be written to the zip
destFolder - the folder to write the Zip file to
zipName - the name the zip file should have. If no zipName is passed, the name of the folder will be used.
compress - true if the file shoukld be compressed, false if not.
Returns:
a zip(64) File

createZipAndCheck

public static ZipResult createZipAndCheck(File srcFolder,
                                          File destFolder,
                                          String zipName,
                                          boolean compress)
Creates a Zip64File containing all the files in srcFolder and write it to destFolder using the passed zipName. After creating the zip file, a checksum is calculated.

Parameters:
srcFolder - the folder containing the files to be written to the zip
destFolder - the folder to write the Zip file to
zipName - the name the zip file should have. If no zipName is passed, the name of the folder will be used.
compress - has no effect TODO implement compression
Returns:
a ZipResult, containing the zip as a file and the created checksum (MD5)

unzipTo

public static List<File> unzipTo(File zipFile,
                                 File destFolder)
Unzips a zip file and writes the contained files to destFolder.

Parameters:
zipFile - the zip file to unpack.
destFolder - the folder to write the extracted files to.
Returns:
a List with all extracted files.

checkAndUnzipTo

public static List<File> checkAndUnzipTo(File zipFile,
                                         File destFolder,
                                         Checksum checksum)
Unzips a zip file and writes the content to destFolder, checking if the checksum is correct.

Parameters:
zipFile - the file to unpack
destFolder - the folder to write the content of the zip to
checksum - the checksum to check
Returns:
a list containing all extracted files.

getAllFragments

public static String[] getAllFragments(File zip)
A convenience method. It creates an array of fragments from all entries in a given zip file. Fragments can be used to adress entries in a zip file.

Parameters:
zip - the zip file to scan
Returns:
an String[] containing all file entries in this zip.

getFileFrom

public static File getFileFrom(File zip,
                               String targetPathInZipfile,
                               File destFolder)
Extracts a file specified by targetPathInZipfile from the passed zip and writes it to destFolder. If the targetPathInZipfile points to a folder, all files in the folder will be extracted as well and the parent folder, containing all these files, is returned.

Parameters:
zip - the zip to extract targetPathInZipfile from
targetPathInZipfile - the file to extract
destFolder - the folder to write the extrcated file to
Returns:
the extracted File.

insertFileInto

public static File insertFileInto(File zipFile,
                                  File toInsert,
                                  String targetPath)
Inserts a file into a given zip at a location specified by targetPath. If toInsert points to a folder, all files in this folder will be added to the zip. If the zip already contains a file specified by targetPath, the existing entry (and all files contained in it) will be deleted and toInsert (and all contained files) is inserted.

Parameters:
zipFile - the zip file where the file toInsert will be added.
toInsert - the file to add to the zip
targetPath - the location the file should have in this zip
Returns:
the modified zip, containing the file toInsert.

removeFileFrom

public static File removeFileFrom(File zipFile,
                                  String fileToRemove)
Removes the file 'fileToRemove' from zipFile. 'fileToRemove' points to the location of the file to delete inside the zip file.

Parameters:
zipFile - the zip file to remove fileToRemove from.
fileToRemove - the path of the file to remove from zipFile.
Returns:
the modified zipFile.

isZipFile

public static boolean isZipFile(File file)

listZipEntries

public static List<String> listZipEntries(File zip)
Lists all entries in this zip file. Each entry is a file/folder in this zip.

Parameters:
zip - the zip file to scan
Returns:
a list with all entry paths


Copyright © 2013 Open Planets Foundation. All Rights Reserved.