Class Zip

java.lang.Object
de.hsh.graja.util.Zip

public class Zip extends Object
  • Constructor Details

    • Zip

      public Zip()
  • Method Details

    • isZipFile

      public static boolean isZipFile(File f)
      Checks, if f can be read as a zip file.
      Parameters:
      f - the file
      Returns:
      true, if can be read as a zip file.
    • isZipFile

      public static boolean isZipFile(InputStream is)
      Checks, if is can be read as a zip file.
      Parameters:
      is - the input stream
      Returns:
      true, if can be read as a zip file.
    • isZipFile

      public static boolean isZipFile(byte[] data)
      Checks, if data can be read as a zip file.
      Parameters:
      data - the input data
      Returns:
      true, if can be read as a zip file.
    • zipDir

      public static Zip.ZipResult zipDir(Path dir2zip) throws IOException
      Zips the contents of dir2zip to the file dir2zip.getParent().resolve(dir2zip.getName(dir2zip.getNameCount()-1)+".zip" Zip entries are created as relative entries with respect to dir2zip's parent directory.
      Parameters:
      dir2zip -
      Throws:
      IOException
    • zipDir

      public static Zip.ZipResult zipDir(Path dir2zip, String toZipFile) throws IOException
      Zips the contents of dir2zip to the file located at toZipFile. Zip entries are created as relative entries with respect to dir2zip's parent directory.
      Parameters:
      dir2zip -
      toZipFile -
      Throws:
      IOException
    • zipDir

      public static Zip.ZipResult zipDir(Path dir2zip, Path baseDir, String toZipFile) throws IOException
      Zips the contents of dir2zip to the file located at toZipFile. Zip entries are created as relative entries with respect to baseDir.
      Parameters:
      dir2zip -
      baseDir -
      toZipFile -
      Throws:
      IOException
    • zipInMemorySingleFile

      public static Zip.ZipResult zipInMemorySingleFile(Zip.ZipContentElement source, OutputStream os) throws IOException
      Read element from source and write it as a zip file to os.
      Parameters:
      source -
      os -
      Returns:
      Throws:
      IOException
    • zipInMemoryElements

      public static Zip.ZipResult zipInMemoryElements(List<Zip.ZipContentElement> source, OutputStream os) throws IOException
      Read elements from source and write them as a zip file to os.
      Parameters:
      source -
      os -
      Returns:
      Throws:
      IOException
    • unzipInMemoryElements

      public static Zip.ZipResult unzipInMemoryElements(byte[] input, List<Zip.ZipContentElement> output) throws IOException
      Throws:
      IOException
    • unzip

      public static Zip.ZipResult unzip(File file, File destDir) throws IOException
      Unzips the zip file "file" into the directory "dest"
      Parameters:
      file - The zip file
      destDir - Directory where the content of the zip file will be saved
      Throws:
      IOException - thrown, when unzip has not succeeded
    • unzipEntry

      public static byte[] unzipEntry(File file, String entry) throws IOException
      Unzips the zip file "file" into the directory "dest"
      Parameters:
      file - The zip file
      entry - entry name
      Throws:
      IOException - thrown, when unzip has not succeeded
    • addFilesToExistingZip

      public static void addFilesToExistingZip(File zipFile, Path baseDir, File[] entries) throws IOException
      Throws:
      IOException