Klasse ZIPHelper

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

public final class ZIPHelper extends Object
All the zip operations are handled.
Autor:
Andreas Enders
  • Konstruktordetails

    • ZIPHelper

      public ZIPHelper()
  • Methodendetails

    • createZIPWithPathEntries

      public static void createZIPWithPathEntries(File aDirectory, File aZipFile) throws ZipException
      Packs the given directory into a new zip file with the given name
      Parameter:
      aDirectory -
      aZipFile -
      Löst aus:
      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.) *
      Parameter:
      aFilesCollection -
      aDestinationFile -
      aParentStartPath -
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aDestinationDir -
      Löst aus:
      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.
      Parameter:
      aZipFile -
      aDir -
      aExtension -
      aOlderThanMillis -
      Gibt zurück:
      success
    • createZIP

      public static void createZIP(Collection<File> aFilesCollection, File aDestinationFile) throws ZipException
      Creates a zip file out of a collection of files.
      Parameter:
      aFilesCollection -
      aDestinationFile -
      Löst aus:
      ZipException
    • createZIP

      public static void createZIP(String aFileName, InputStream aInputStream, File aDestinationFile) throws ZipException
      Creates a zip file out of a InputStream.
      Parameter:
      aFileName -
      aInputStream -
      aDestinationFile -
      Löst aus:
      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.
      Parameter:
      aFilesCollection -
      aSourceZipFile -
      aDestinationZipFile -
      Löst aus:
      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.
      Parameter:
      aFileToAdd -
      aSourceZipFile -
      aDestinationZipFile -
      Löst aus:
      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.
      Parameter:
      aZipEntriesColl -
      aSourceZipFile -
      aDestinationZipFile -
      Gibt zurück:
      a new Zip file
      Löst aus:
      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
      Parameter:
      aSourceZipFile -
      aDestinationDir -
      Gibt zurück:
      a list of unzipped-files
      Löst aus:
      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
      Parameter:
      aSourceZipFile -
      aDestinationDir -
      aReplacePercentInPath -
      Gibt zurück:
      a list of unzipped-files
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aSubPath -
      aDestinationDir -
      Gibt zurück:
      a list of unzipped-files
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aSubPath -
      aDestinationDir -
      aReplacePercentInPath -
      Gibt zurück:
      a list of unzipped-files
      Löst aus:
      ZipException
    • getZIPEntries

      public static Collection<? extends ZipEntry> getZIPEntries(File aSourceZipFile) throws ZipException
      Extracts the entries of the given zip-file.
      Parameter:
      aSourceZipFile -
      Gibt zurück:
      Collection of the entries of the given zip-file
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aName -
      Gibt zurück:
      the entries of a zip file which contains the given name
      Löst aus:
      ZipException
    • getZIPEntriesWithoutPathName

      public static Collection<ZipEntry> getZIPEntriesWithoutPathName(File aSourceZipFile, String aName) throws ZipException
      Returns the entries of a zip file without the given name.
      Parameter:
      aSourceZipFile -
      aName -
      Gibt zurück:
      the entries of a zip file without the given name
      Löst aus:
      ZipException
    • getZIPEntry

      public static ZipEntry getZIPEntry(File aSourceZipFile, String aFileName) throws ZipException
      Get the entries of a zip file
      Parameter:
      aSourceZipFile -
      aFileName -
      Gibt zurück:
      the entries of a zip file
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aFileName -
      Gibt zurück:
      the zip entry of the given file name with out the path info
      Löst aus:
      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.
      Parameter:
      aFilenameList -
      aSourceZipFile -
      aDestinationZipFile -
      Löst aus:
      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.
      Parameter:
      aFilename -
      aSourceZipFile -
      aDestinationZipFile -
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aDestinationFile -
      aFileName -
      Gibt zurück:
      success
      Löst aus:
      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.
      Parameter:
      aSourceZipFile -
      aFileName -
      aDestinationFile -
      Gibt zurück:
      success
      Löst aus:
      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.
      Parameter:
      aZipArchive -
      Gibt zurück:
      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.
      Parameter:
      aSourceFile -
      aDestinationFile -
      Löst aus:
      ZipException