Class ZipPrefixer

java.lang.Object
net.e175.klaus.zip.ZipPrefixer

public final class ZipPrefixer extends Object
  • Method Details

    • applyPrefixesToZip

      public static long applyPrefixesToZip(Path targetPath, byte[]... prefixes) throws IOException
      Prepend prefix(es) to an existing ZIP format file, adjusting internal offsets as needed. This method tries to be as cautious as possible by verifying the original ZIP file before proceeding with prefixing and adjustment.
      Parameters:
      targetPath - Target ZIP file. Must be a writeable ZIP format file, in a writeable directory with enough space to hold a temporary copy.
      prefixes - Binary prefixes that will be sequentially written before the original ZIP file's contents.
      Returns:
      Total number of bytes written as prefixes.
      Throws:
      IOException - on errors related to I/O and ZIP integrity
    • applyPrefixesToZip

      public static long applyPrefixesToZip(Path targetPath, Collection<Path> prefixFiles) throws IOException
      Prepend prefix(es) to an existing ZIP format file, adjusting internal offsets as needed. This method tries to be as cautious as possible by verifying the original ZIP file before proceeding with prefixing and adjustment.
      Parameters:
      targetPath - Target ZIP file. Must be a writeable ZIP format file, in a writeable directory with enough space to hold a temporary copy.
      prefixFiles - Prefix files that will be sequentially written before the original file's contents.
      Returns:
      Total number of bytes written as prefixes.
      Throws:
      IOException - on errors related to I/O and ZIP integrity
    • applyPrefixes

      public static long applyPrefixes(Path targetPath, byte[]... prefixes) throws IOException
      Prepend prefix(es) to an existing file. This method does not care about file types or contents, it just mechanically glues the bytes together.
      Parameters:
      targetPath - Target file. Must be writeable, in a writeable directory with enough space to hold a temporary copy.
      prefixes - Binary prefixes that will be sequentially written before the original file's contents.
      Returns:
      Total number of bytes written as prefixes.
      Throws:
      IOException - on I/O related errors
    • applyPrefixes

      public static long applyPrefixes(Path targetPath, Collection<Path> prefixFiles) throws IOException
      Prepend prefix files to an existing file. This method does not care about file types or contents, it just mechanically glues the bytes together.
      Parameters:
      targetPath - Target file. Must be writeable, in a writeable directory with enough space to hold a temporary copy.
      prefixFiles - Prefix files that will be sequentially written before the original file's contents.
      Returns:
      Total number of bytes written as prefixes.
      Throws:
      IOException - on I/O related errors
    • validateZipOffsets

      public static void validateZipOffsets(Path targetPath) throws IOException
      Validate current offsets in ZIP file.
      Parameters:
      targetPath - ZIP file to process.
      Throws:
      IOException - On I/O errors.
      ZipException - On errors in the ZIP's integrity.
    • adjustZipOffsets

      public static void adjustZipOffsets(Path targetPath, long adjustment) throws IOException
      Adjust offsets in ZIP file (with validation). If adjustment is 0, don't write anything, just validate.
      Parameters:
      targetPath - ZIP file to process.
      adjustment - Offset to add to the current offsets.
      Throws:
      IOException - On I/O errors.
      ZipException - On errors in the ZIP's integrity.
    • main

      public static void main(String... args) throws IOException
      Rudimentary CLI intended for testing only.
      Throws:
      IOException