java.lang.Object
org.miaixz.bus.extra.compress.archiver.StreamArchiver
- All Implemented Interfaces:
Closeable,AutoCloseable,Archiver
Data archiver wrapper, which archives several files or directories into a compressed package. Supported archive file
formats are:
ArchiveStreamFactory.ARArchiveStreamFactory.CPIOArchiveStreamFactory.JARArchiveStreamFactory.TARArchiveStreamFactory.ZIP
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionStreamArchiver(Charset charset, String archiverName, File file) Constructor.StreamArchiver(Charset charset, String archiverName, OutputStream targetStream) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdds a file or directory to the archive package.voidclose()Closes without throwing an exception.finish()Finishes archiving the added files.static StreamArchiverCreates an archiver.static StreamArchiverof(Charset charset, String archiverName, OutputStream out) Creates an archiver.
-
Constructor Details
-
StreamArchiver
Constructor.- Parameters:
charset- The character encoding.archiverName- The name of the archive format, seeArchiveStreamFactory.file- The output archive file.
-
StreamArchiver
Constructor.- Parameters:
charset- The character encoding.archiverName- The name of the archive format, seeArchiveStreamFactory.targetStream- The output stream for the archive.
-
-
Method Details
-
of
Creates an archiver.- Parameters:
charset- The character encoding.archiverName- The name of the archive format, seeArchiveStreamFactory.file- The output archive file.- Returns:
- A new StreamArchiver instance.
-
of
Creates an archiver.- Parameters:
charset- The character encoding.archiverName- The name of the archive format, seeArchiveStreamFactory.out- The output stream for the archive.- Returns:
- A new StreamArchiver instance.
-
add
public StreamArchiver add(File file, String path, Function<String, String> fileNameEditor, Predicate<File> predicate) throws org.miaixz.bus.core.lang.exception.InternalExceptionDescription copied from interface:ArchiverAdds a file or directory to the archive package. Directories are added recursively level by level.- Specified by:
addin interfaceArchiver- Parameters:
file- The file or directory.path- The initial path of the file or directory. If null, it is placed at the root level.fileNameEditor- A function to edit the file name.predicate- A file filter that specifies which files or directories can be added. IfPredicate.test(Object)istrue, the file is kept. If null, all are added.- Returns:
- this
- Throws:
org.miaixz.bus.core.lang.exception.InternalException
-
finish
Finishes archiving the added files. This method does not close the archive stream, allowing more files to be added. -
close
public void close()Description copied from interface:ArchiverCloses without throwing an exception.
-