Class ZipPackager

java.lang.Object
com.powsybl.commons.compress.ZipPackager

public class ZipPackager extends Object
Author:
Yichen TANG <yichen.tang at rte-france.com>
  • Constructor Details

    • ZipPackager

      public ZipPackager()
  • Method Details

    • addPath

      public ZipPackager addPath(@Nullable Path path)
      If the path to file is null or not exists, the method does nothing. If the file is in .gz(detected by last 3 characters) format, the method decompresses .gz file first.
      Parameters:
      path - the file to add in zip bytes
      Returns:
      a reference to this object
    • addPaths

      public ZipPackager addPaths(Path baseDir, List<String> filenames)
      Parameters:
      baseDir - the base directory of all files
      filenames - all files to add in zip bytes
      Returns:
      a reference to this object
    • addPaths

      public ZipPackager addPaths(Path root, String... filenames)
      Parameters:
      baseDir - the base directory of all files
      filenames - all files to add in zip bytes
      Returns:
      a reference to this object
    • addString

      public ZipPackager addString(String key, String content)
      Key as zip entry name. Both key and content must not be null.
      Parameters:
      key -
      content -
      Returns:
      a reference to this object
    • addString

      public ZipPackager addString(String key, String content, Charset charset)
      Key as zip entry name. Both key and content must not be null.
      Parameters:
      key -
      content -
      charset - be used to encode content
      Returns:
      a reference to this object
    • addBytes

      public ZipPackager addBytes(String key, byte[] bytes)
      Key as zip entry name. Both key and bytes must not be null.
      Parameters:
      key -
      bytes -
      Returns:
      a reference to this object
    • toZipBytes

      public byte[] toZipBytes()
      Should only be called once.
      Returns:
      an array of zip bytes
    • archiveFilesToZipBytes

      public static byte[] archiveFilesToZipBytes(Path baseDir, List<String> fileNames)
      If the file is in .gz(detected by last 3 characters) format, the method decompresses .gz file first.
      Parameters:
      baseDir - the base directory contaions files to zip
      fileNames - the files to be added in zip
      Returns:
      bytes in zip format
    • archiveFilesToZipBytes

      public static byte[] archiveFilesToZipBytes(Path workingDir, String... fileNames)
    • archiveBytesByNameToZipBytes

      public static byte[] archiveBytesByNameToZipBytes(Map<String,byte[]> bytesByName)
      Generates a zip file's bytes
      Parameters:
      bytesByName - map's key as entry name, value as content in the zip file
      Returns:
      a zip file in bytes