java.lang.Object
org.miaixz.bus.extra.compress.CompressBuilder
Compression utility class. A wrapper for compression and decompression based on commons-compress.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ArchivercreateArchiver(Charset charset, String archiverName, File file) Creates an archiver.static ArchivercreateArchiver(Charset charset, String archiverName, OutputStream out) Creates an archiver.static ExtractorcreateExtractor(Charset charset, File file) Creates an archive extractor.static ExtractorcreateExtractor(Charset charset, InputStream in) Creates an archive extractor.static ExtractorcreateExtractor(Charset charset, String archiverName, File file) Creates an archive extractor.static ExtractorcreateExtractor(Charset charset, String archiverName, InputStream in) Creates an archive extractor.static StringGets the archive entry name.static org.apache.commons.compress.compressors.CompressorInputStreamgetIn(String compressorName, InputStream in) Gets a compression input stream for decompressing specified content.static org.apache.commons.compress.compressors.CompressorOutputStreamgetOut(String compressorName, OutputStream out) Gets a compression output stream for compressing specified content.
-
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
Creates an archiver. Supported formats:ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIPArchiveStreamFactory.SEVEN_Z
- Parameters:
charset- The character encoding.archiverName- The name of the archiver format, seeArchiveStreamFactory.file- The output archive file.- Returns:
- An Archiver instance.
-
createArchiver
Creates an archiver. Supported formats:ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIPArchiveStreamFactory.SEVEN_Z
- Parameters:
charset- The character encoding.archiverName- The name of the archiver format, seeArchiveStreamFactory.out- The output stream for the archive.- Returns:
- An Archiver instance.
-
createExtractor
Creates an archive extractor. Supported formats:ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIPArchiveStreamFactory.SEVEN_Z
- Parameters:
charset- The character encoding. This parameter is ignored for the 7z format.file- The archive file.- Returns:
- An
Extractor.
-
createExtractor
Creates an archive extractor. Supported formats:ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIPArchiveStreamFactory.SEVEN_Z
- Parameters:
charset- The character encoding. This parameter is ignored for the 7z format.archiverName- The name of the archiver format, seeArchiveStreamFactory. null means auto-detect.file- The archive file.- Returns:
- An
Extractor.
-
createExtractor
Creates an archive extractor. Supported formats:ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIPArchiveStreamFactory.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
Creates an archive extractor. Supported formats:ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIPArchiveStreamFactory.SEVEN_Z
- Parameters:
charset- The character encoding. This parameter is ignored for the 7z format.archiverName- The name of the archiver format, seeArchiveStreamFactory. 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.
-