Class TARHelper

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

public final class TARHelper extends Object
All the tar operations are handled.
Author:
Andreas Enders
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addToTar(File aFileToAdd, File aSourceZipFile, File aDestinationZipFile)
    Add a file(s) to the zip file from a collection of files.
    static void
    addToTar(Collection<File> aFilesCollection, File aSourceTarFile, File aDestinationTarFile)
    Add a file(s) to the zip file from a collection of files.
    static void
    createTar(String aFileName, InputStream aInputStream, File aDestinationFile, boolean doGZIP)
    Creates a zip file out of a InputStream.
    static void
    createTar(Collection<File> aFilesCollection, File aDestinationFile, boolean doGZIP)
    Creates a zip file out of a collection of files.
    static void
    createTARWithPathEntries(File aDirectory, File aTarFile, boolean doGZIP)
    Packs the given directory into a new zipfile with the given name
    static void
    createTARWithPathEntries(Collection<File> aFilesCollection, File aDestinationFile, String aParentStartPath, boolean doGZIP)
    Creates a zip file out of a collection of files.
    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.
    static Collection<com.ice.tar.TarEntry>
    getTAREntries(File aSourceTarFile, boolean doUnGZIP)
    Extracts the entries of the given zip-file.
    static File
    gz(File aSourceFile)
    Packs the given directory into a new zipfile with the given name
    static File
    gz(File aSourceFile, boolean doDeletSourceFile)
    Packs the given directory into a new zipfile with the given name
    static File
    gz(File aSourceFile, File aDestFile)
    Packs the given directory into a new zipfile with the given name
    static File
    gz(File aSourceFile, File aDestFile, boolean doDeletSourceFile)
    Packs the given directory into a new zipfile with the given name
    static final boolean
    packAndDeleteDirContents(File aTarFile, File aDir, String aExtension, long aOlderThanMillis, boolean doGZIP)
    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.
    static final boolean
    packDirContents(File aTarFile, File aDir, String aExtension, long aOlderThanMillis, boolean doGZIP)
    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.
    static File
    ungz(File aSourceFile)
    Packs the given directory into a new zipfile with the given name
    static File
    ungz(File aSourceFile, boolean doDeleteSourceFile)
    Packs the given directory into a new zipfile with the given name
    static File
    ungz(File aSourceFile, File aDestFile)
    Packs the given directory into a new zipfile with the given name
    static File
    ungz(File aSourceFile, File aDestFile, boolean doDeleteSourceFile)
    Packs the given directory into a new zipfile with the given name
    static List<File>
    unTar(File aSourceTarFile, String aDestinationDir, boolean aReplacePercentInPath, boolean doUnGZIP)
    UnTars a Tar file to the given directory and returns a map of unTarped-files
    static List<File>
    unTar(File aSourceTarFile, String aSubPath, String aDestinationDir, boolean doUnGZIP)
    Unzips a zip file to the given directory and returns a map of unzipped-files.
    static List<File>
    unTar(File aSourceTarFile, String aSubPath, String aDestinationDir, boolean aReplacePercentInPath, boolean doUnGZIP)
    Unzips a zip file to the given directory and returns a map of unzipped-files.
    static List<File>
    unTAR(File aSourceTarFile, String aDestinationDir, boolean doUnGZIP)
    Unzips a zip file to the given directory and returns a map of unzipped-files
    static void
    unTarWithPath(File aSourceTarFile, String aDestinationDir, boolean doUnGZIP)
    Unzips a zip file to the given directory structure as how the zipentry specifies.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • gz

      public static File gz(File aSourceFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • gz

      public static File gz(File aSourceFile, boolean doDeletSourceFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      doDeletSourceFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • gz

      public static File gz(File aSourceFile, File aDestFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      aDestFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • gz

      public static File gz(File aSourceFile, File aDestFile, boolean doDeletSourceFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      aDestFile -
      doDeletSourceFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • ungz

      public static File ungz(File aSourceFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      aDestFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • ungz

      public static File ungz(File aSourceFile, boolean doDeleteSourceFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      doDeleteSourceFile -
      aDestFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • ungz

      public static File ungz(File aSourceFile, File aDestFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      aDestFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • ungz

      public static File ungz(File aSourceFile, File aDestFile, boolean doDeleteSourceFile) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aSourceFile -
      aDestFile -
      doDeleteSourceFile -
      Returns:
      a new zipfile with the given name
      Throws:
      ZipException
    • createTARWithPathEntries

      public static void createTARWithPathEntries(File aDirectory, File aTarFile, boolean doGZIP) throws ZipException
      Packs the given directory into a new zipfile with the given name
      Parameters:
      aDirectory -
      aTarFile -
      doGZIP -
      Throws:
      ZipException
    • createTARWithPathEntries

      public static void createTARWithPathEntries(Collection<File> aFilesCollection, File aDestinationFile, String aParentStartPath, boolean doGZIP) 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 zipentry.) *
      Parameters:
      aFilesCollection -
      aDestinationFile -
      aParentStartPath -
      doGZIP -
      Throws:
      ZipException
    • unTarWithPath

      public static void unTarWithPath(File aSourceTarFile, String aDestinationDir, boolean doUnGZIP) 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:
      aSourceTarFile -
      aDestinationDir -
      doUnGZIP -
      Throws:
      ZipException
    • packAndDeleteDirContents

      public static final boolean packAndDeleteDirContents(File aTarFile, File aDir, String aExtension, long aOlderThanMillis, boolean doGZIP)
      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:
      aTarFile -
      aDir -
      aExtension -
      aOlderThanMillis -
      doGZIP -
      Returns:
      success
    • packDirContents

      public static final boolean packDirContents(File aTarFile, File aDir, String aExtension, long aOlderThanMillis, boolean doGZIP)
      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:
      aTarFile -
      aDir -
      aExtension -
      aOlderThanMillis -
      doGZIP -
      Returns:
      success
    • createTar

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

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

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

      public static void addToTar(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
    • unTAR

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

      public static List<File> unTar(File aSourceTarFile, String aDestinationDir, boolean aReplacePercentInPath, boolean doUnGZIP) throws ZipException
      UnTars a Tar file to the given directory and returns a map of unTarped-files
      Parameters:
      aSourceTarFile -
      aDestinationDir -
      aReplacePercentInPath -
      doUnGZIP -
      Returns:
      a list of unTarped-files
      Throws:
      ZipException
    • unTar

      public static List<File> unTar(File aSourceTarFile, String aSubPath, String aDestinationDir, boolean doUnGZIP) 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:
      aSourceTarFile -
      aSubPath -
      aDestinationDir -
      doUnGZIP -
      Returns:
      a list of unzipped-files
      Throws:
      ZipException
    • unTar

      public static List<File> unTar(File aSourceTarFile, String aSubPath, String aDestinationDir, boolean aReplacePercentInPath, boolean doUnGZIP) 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:
      aSourceTarFile -
      aSubPath -
      aDestinationDir -
      aReplacePercentInPath -
      doUnGZIP -
      Returns:
      a list of unzipped-files
      Throws:
      ZipException
    • getTAREntries

      public static Collection<com.ice.tar.TarEntry> getTAREntries(File aSourceTarFile, boolean doUnGZIP) throws ZipException
      Extracts the entries of the given zip-file.
      Parameters:
      aSourceTarFile -
      doUnGZIP -
      Returns:
      the entries of the given zip-file
      Throws:
      ZipException
    • 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