Class ZIPHelper

java.lang.Object
net.simplace.core.service.ZIPHelper

public final class ZIPHelper extends Object
All the zip operations are handled.
Author:
Andreas Enders
  • Constructor Details

    • ZIPHelper

      public ZIPHelper()
  • Method Details

    • createZIPWithPathEntries

      public static void createZIPWithPathEntries(File aDirectory, File aZipFile) throws ZipException
      Packs the given directory into a new zip file with the given name
      Parameters:
      aDirectory -
      aZipFile -
      Throws:
      ZipException
    • createZIPWithPathEntries

      public static void createZIPWithPathEntries(Collection<File> 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.) *
      Parameters:
      aFilesCollection -
      aDestinationFile -
      aParentStartPath -
      Throws:
      ZipException
    • unZIPWithPath

      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.
      Parameters:
      aSourceZipFile -
      aDestinationDir -
      Throws:
      ZipException
    • packAndDeleteDirContents

      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.
      Parameters:
      aZipFile -
      aDir -
      aExtension -
      aOlderThanMillis -
      Returns:
      success
    • createZIP

      public static void createZIP(Collection<File> aFilesCollection, File aDestinationFile) throws ZipException
      Creates a zip file out of a collection of files.
      Parameters:
      aFilesCollection -
      aDestinationFile -
      Throws:
      ZipException
    • createZIP

      public static void createZIP(String aFileName, InputStream aInputStream, File aDestinationFile) throws ZipException
      Creates a zip file out of a InputStream.
      Parameters:
      aFileName -
      aInputStream -
      aDestinationFile -
      Throws:
      ZipException
    • addToZIP

      public static void addToZIP(Collection<File> aFilesCollection, File aSourceZipFile, File aDestinationZipFile) throws ZipException
      Add a file(s) to the zip file from a collection of files.
      Parameters:
      aFilesCollection -
      aSourceZipFile -
      aDestinationZipFile -
      Throws:
      ZipException
    • addToZIP

      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.
      Parameters:
      aFileToAdd -
      aSourceZipFile -
      aDestinationZipFile -
      Throws:
      ZipException
    • createZIP

      public static File createZIP(Collection<ZipEntry> aZipEntriesColl, File aSourceZipFile, File aDestinationZipFile) throws ZipException
      Generates a new Zip file out of an existing zip file with specific zip entries only.
      Parameters:
      aZipEntriesColl -
      aSourceZipFile -
      aDestinationZipFile -
      Returns:
      a new Zip file
      Throws:
      ZipException
    • unZIP

      public static List<File> unZIP(File aSourceZipFile, String aDestinationDir) throws ZipException
      Unzips a zip file to the given directory and returns a map of unzipped-files
      Parameters:
      aSourceZipFile -
      aDestinationDir -
      Returns:
      a list of unzipped-files
      Throws:
      ZipException
    • unZIP

      public static List<File> unZIP(File aSourceZipFile, String aDestinationDir, boolean aReplacePercentInPath) throws ZipException
      Unzips a zip file to the given directory and returns a map of unzipped-files
      Parameters:
      aSourceZipFile -
      aDestinationDir -
      aReplacePercentInPath -
      Returns:
      a list of unzipped-files
      Throws:
      ZipException
    • unZIP

      public static List<File> 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.
      Parameters:
      aSourceZipFile -
      aSubPath -
      aDestinationDir -
      Returns:
      a list of unzipped-files
      Throws:
      ZipException
    • unZIP

      public static List<File> 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.
      Parameters:
      aSourceZipFile -
      aSubPath -
      aDestinationDir -
      aReplacePercentInPath -
      Returns:
      a list of unzipped-files
      Throws:
      ZipException
    • getZIPEntries

      public static Collection<? extends ZipEntry> getZIPEntries(File aSourceZipFile) throws ZipException
      Extracts the entries of the given zip-file.
      Parameters:
      aSourceZipFile -
      Returns:
      Collection of the entries of the given zip-file
      Throws:
      ZipException
    • getZIPEntriesHavingPathName

      public static Collection<ZipEntry> getZIPEntriesHavingPathName(File aSourceZipFile, String aName) throws ZipException
      Returns the entries of a zip file which contains the given name.
      Parameters:
      aSourceZipFile -
      aName -
      Returns:
      the entries of a zip file which contains the given name
      Throws:
      ZipException
    • getZIPEntriesWithoutPathName

      public static Collection<ZipEntry> getZIPEntriesWithoutPathName(File aSourceZipFile, String aName) throws ZipException
      Returns the entries of a zip file without the given name.
      Parameters:
      aSourceZipFile -
      aName -
      Returns:
      the entries of a zip file without the given name
      Throws:
      ZipException
    • getZIPEntry

      public static ZipEntry getZIPEntry(File aSourceZipFile, String aFileName) throws ZipException
      Get the entries of a zip file
      Parameters:
      aSourceZipFile -
      aFileName -
      Returns:
      the entries of a zip file
      Throws:
      ZipException
    • getZIPEntryExcludingPath

      public static ZipEntry getZIPEntryExcludingPath(File aSourceZipFile, String aFileName) throws ZipException
      Returs the zip entry of the given file name with out the path info.
      Parameters:
      aSourceZipFile -
      aFileName -
      Returns:
      the zip entry of the given file name with out the path info
      Throws:
      ZipException
    • removeZipEntry

      public static void removeZipEntry(List<String> aFilenameList, File aSourceZipFile, File aDestinationZipFile) throws ZipException
      Add a file(s) to the zip file from a collection of files.
      Parameters:
      aFilenameList -
      aSourceZipFile -
      aDestinationZipFile -
      Throws:
      ZipException
    • removeZipEntry

      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.
      Parameters:
      aFilename -
      aSourceZipFile -
      aDestinationZipFile -
      Throws:
      ZipException
    • readZIPEntry

      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.
      Parameters:
      aSourceZipFile -
      aDestinationFile -
      aFileName -
      Returns:
      success
      Throws:
      ZipException
      IOException
    • readZIPEntry

      public static String[][] readZIPEntry(File aSourceZipFile, String aFileName, String aDivider) throws ZipException, IOException
      This method reads a given file out of a ZipFile and writes it to the destination file.
      Parameters:
      aSourceZipFile -
      aDestinationFile -
      aFileName -
      Returns:
      success
      Throws:
      ZipException
      IOException
    • getFileSeparator

      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.
      Parameters:
      aZipArchive -
      Returns:
      file separator
    • flattenZipArchive

      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.
      Parameters:
      aSourceFile -
      aDestinationFile -
      Throws:
      ZipException