Class Zips

java.lang.Object
org.eclipse.cbi.common.util.Zips

public class Zips extends Object
Utility class to work with Zip files (Path based).
  • Field Details

  • Constructor Details

    • Zips

      public Zips()
  • Method Details

    • unpackZip

      public static int unpackZip(Path source, Path outputDir) throws IOException
      Unzip the given source Zip file in the outputDir.
      Parameters:
      source - the file to unzip.
      outputDir - the output directory where the Zip will be unpacked.
      Returns:
      the number of unpacked entries
      Throws:
      IOException
    • fixPosixPermissions

      private static void fixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path entryPath)
    • unpack

      private static int unpack(org.apache.commons.compress.archivers.zip.ZipFile zipFile, Path outputDir, BiConsumer<org.apache.commons.compress.archivers.zip.ZipArchiveEntry,Path> entryFixer) throws IOException, ZipException
      Throws:
      IOException
      ZipException
    • unpackZipEntry

      private static Path unpackZipEntry(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path outputDir) throws IOException, ZipException
      Throws:
      IOException
      ZipException
    • unpackJar

      public static int unpackJar(Path source, Path outputDir) throws IOException
      Unzip the given source Jar file in the outputDir.
      Parameters:
      source - the file to unzip.
      outputDir - the output directory where the Jar will be unpacked. It does not have to exist beforehand.
      Returns:
      the number of unpacked entries
      Throws:
      IOException
    • unpackTarGz

      public static int unpackTarGz(Path sourcePath, Path outputDir) throws IOException
      Throws:
      IOException
    • unpack

      static int unpack(org.apache.commons.compress.archivers.tar.TarArchiveInputStream zis, Path outputDir) throws IOException
      Throws:
      IOException
    • setPermissions

      private static void setPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, Path entryPath) throws IOException
      Throws:
      IOException
    • packZip

      public static int packZip(Path source, Path targetZip, boolean preserveRoot) throws IOException
      Zip the given source file or folder in the targetZip Zip file. If preserveRoot is set to true, the output Zip will contain the folder and its contents, only its contents otherwise.
      Parameters:
      source - the folder to zip.
      targetZip - the Zip file to create or overwrite.
      preserveRoot - whether the source folder should be kept in the target Zip.
      Returns:
      the number of packed entries
      Throws:
      IOException
    • packJar

      public static int packJar(Path source, Path targetJar, boolean preserveRoot) throws IOException
      Zip the given source file or folder in the targetJar Jar file. If preserveRoot is set to true, the output Zip will contain the folder and its contents, only its contents otherwise.
      Parameters:
      source - the folder to zip.
      targetJar - the Jar file to create or overwrite.
      preserveRoot - whether the source folder should be kept in the target Jar.
      Returns:
      the number of packed entries
      Throws:
      IOException
    • packManifestIfAny

      private static Set<Path> packManifestIfAny(Path source, org.apache.commons.compress.archivers.jar.JarArchiveOutputStream jos) throws IOException
      Looks for META-INF/MANIFEST.MF file in the given source folder and add them as entries to the JarOutputStream.
      Parameters:
      source - the folder to jar. If not a directory, returns 0 and do nothing
      jos - the jar output stream to write
      preserveRoot - whether the root folder
      Returns:
      set of paths to the META-INF and MANIFEST.MF, empty set otherwise.
      Throws:
      IOException
    • checkPathExists

      private static Path checkPathExists(Path source, String msg)
    • newBufferedOutputStream

      private static BufferedOutputStream newBufferedOutputStream(Path path) throws IOException
      Throws:
      IOException
    • packEntries

      private static int packEntries(Path source, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, boolean preserveRoot, Set<Path> pathToExcludes) throws IOException
      Throws:
      IOException
    • entryNameFrom

      private static String entryNameFrom(Path path, boolean isDirectoryw)
    • putFileEntry

      private static void putFileEntry(Path file, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) throws IOException
      Throws:
      IOException
    • putDirectoryEntry

      private static void putDirectoryEntry(Path dir, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) throws IOException
      Throws:
      IOException
    • createArchiveEntry

      private static org.apache.commons.compress.archivers.zip.ZipArchiveEntry createArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, String entryName)