Module bus.extra

Class CompressBuilder

java.lang.Object
org.miaixz.bus.extra.compress.CompressBuilder

public class CompressBuilder extends Object
Compression utility class. A wrapper for compression and decompression based on commons-compress.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • CompressBuilder

      public CompressBuilder()
  • Method Details

    • getOut

      public static org.apache.commons.compress.compressors.CompressorOutputStream getOut(String compressorName, OutputStream out)
      Gets a compression output stream for compressing specified content. Supported formats include:
      • "gz"
      • "bzip2"
      • "xz"
      • "pack200"
      • "snappy-framed"
      • "lz4-block"
      • "lz4-framed"
      • "zstd"
      • "deflate"
      Parameters:
      compressorName - The name of the compressor, see: CompressorStreamFactory.
      out - The output stream, which can be to memory, a network, or a file.
      Returns:
      A CompressorOutputStream.
    • getIn

      public static org.apache.commons.compress.compressors.CompressorInputStream getIn(String compressorName, InputStream in)
      Gets a compression input stream for decompressing specified content. Supported formats include:
      • "gz"
      • "bzip2"
      • "xz"
      • "pack200"
      • "snappy-framed"
      • "lz4-block"
      • "lz4-framed"
      • "zstd"
      • "deflate"
      Parameters:
      compressorName - The name of the compressor, see: CompressorStreamFactory. null means auto-detect.
      in - The input stream.
      Returns:
      A CompressorInputStream.
    • createArchiver

      public static Archiver createArchiver(Charset charset, String archiverName, File file)
      Creates an archiver. Supported formats:
      • ArchiveStreamFactory.AR
      • ArchiveStreamFactory.CPIO
      • ArchiveStreamFactory.JAR
      • ArchiveStreamFactory.TAR
      • ArchiveStreamFactory.ZIP
      • ArchiveStreamFactory.SEVEN_Z
      Parameters:
      charset - The character encoding.
      archiverName - The name of the archiver format, see ArchiveStreamFactory.
      file - The output archive file.
      Returns:
      An Archiver instance.
    • createArchiver

      public static Archiver createArchiver(Charset charset, String archiverName, OutputStream out)
      Creates an archiver. Supported formats:
      • ArchiveStreamFactory.AR
      • ArchiveStreamFactory.CPIO
      • ArchiveStreamFactory.JAR
      • ArchiveStreamFactory.TAR
      • ArchiveStreamFactory.ZIP
      • ArchiveStreamFactory.SEVEN_Z
      Parameters:
      charset - The character encoding.
      archiverName - The name of the archiver format, see ArchiveStreamFactory.
      out - The output stream for the archive.
      Returns:
      An Archiver instance.
    • createExtractor

      public static Extractor createExtractor(Charset charset, File file)
      Creates an archive extractor. Supported formats:
      • ArchiveStreamFactory.AR
      • ArchiveStreamFactory.CPIO
      • ArchiveStreamFactory.JAR
      • ArchiveStreamFactory.TAR
      • ArchiveStreamFactory.ZIP
      • ArchiveStreamFactory.SEVEN_Z
      Parameters:
      charset - The character encoding. This parameter is ignored for the 7z format.
      file - The archive file.
      Returns:
      An Extractor.
    • createExtractor

      public static Extractor createExtractor(Charset charset, String archiverName, File file)
      Creates an archive extractor. Supported formats:
      • ArchiveStreamFactory.AR
      • ArchiveStreamFactory.CPIO
      • ArchiveStreamFactory.JAR
      • ArchiveStreamFactory.TAR
      • ArchiveStreamFactory.ZIP
      • ArchiveStreamFactory.SEVEN_Z
      Parameters:
      charset - The character encoding. This parameter is ignored for the 7z format.
      archiverName - The name of the archiver format, see ArchiveStreamFactory. null means auto-detect.
      file - The archive file.
      Returns:
      An Extractor.
    • createExtractor

      public static Extractor createExtractor(Charset charset, InputStream in)
      Creates an archive extractor. Supported formats:
      • ArchiveStreamFactory.AR
      • ArchiveStreamFactory.CPIO
      • ArchiveStreamFactory.JAR
      • ArchiveStreamFactory.TAR
      • ArchiveStreamFactory.ZIP
      • ArchiveStreamFactory.SEVEN_Z
      Parameters:
      charset - The character encoding. This parameter is ignored for the 7z format.
      in - The input stream for the archive.
      Returns:
      An Extractor.
    • createExtractor

      public static Extractor createExtractor(Charset charset, String archiverName, InputStream in)
      Creates an archive extractor. Supported formats:
      • ArchiveStreamFactory.AR
      • ArchiveStreamFactory.CPIO
      • ArchiveStreamFactory.JAR
      • ArchiveStreamFactory.TAR
      • ArchiveStreamFactory.ZIP
      • ArchiveStreamFactory.SEVEN_Z
      Parameters:
      charset - The character encoding. This parameter is ignored for the 7z format.
      archiverName - The name of the archiver format, see ArchiveStreamFactory. null means auto-detect.
      in - The input stream for the archive.
      Returns:
      An Extractor.
    • getEntryName

      public static String getEntryName(String fileName, String path, Function<String,String> fileNameEditor)
      Gets the archive entry name.
      Parameters:
      fileName - The file name, including the main name and extension, but not the path.
      path - The path.
      fileNameEditor - The file name editor.
      Returns:
      The archive entry name.