java.lang.Object
org.miaixz.bus.extra.compress.extractor.StreamExtractor
- All Implemented Interfaces:
Closeable,AutoCloseable,Extractor
Data decompressor, used to extract data from an archive package.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionStreamExtractor(Charset charset, File file) Constructor.StreamExtractor(Charset charset, InputStream in) Constructor.StreamExtractor(Charset charset, String archiverName, File file) Constructor.StreamExtractor(Charset charset, String archiverName, InputStream in) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes without throwing an exception.voidExtracts (decompresses) to the specified directory.Gets the first file stream in the compressed package that meets the specified filter requirements.
-
Constructor Details
-
StreamExtractor
Constructor.- Parameters:
charset- The character encoding.file- The archive file.
-
StreamExtractor
Constructor.- Parameters:
charset- The character encoding.archiverName- The name of the archive format, null for auto-detection.file- The archive file.
-
StreamExtractor
Constructor.- Parameters:
charset- The character encoding.in- The archive stream.
-
StreamExtractor
Constructor.- Parameters:
charset- The character encoding.archiverName- The name of the archive format, null for auto-detection.in- The archive stream.
-
-
Method Details
-
getFirst
public InputStream getFirst(Predicate<org.apache.commons.compress.archivers.ArchiveEntry> predicate) Description copied from interface:ExtractorGets the first file stream in the compressed package that meets the specified filter requirements.- Specified by:
getFirstin interfaceExtractor- Parameters:
predicate- Used to specify the files to be extracted. null means no filtering. Returns the corresponding stream whenPredicate.test(Object)istrue.- Returns:
- The stream of the first file that meets the filter requirements, or
nullif no matching file is found.
-
extract
public void extract(File targetDir, Predicate<org.apache.commons.compress.archivers.ArchiveEntry> predicate) Extracts (decompresses) to the specified directory. The stream is automatically closed after completion. This method can only be called once.- Specified by:
extractin interfaceExtractor- Parameters:
targetDir- The target directory.predicate- A filter for extracted files, used to specify which files to extract. null means no filtering. Extracts whenPredicate.test(Object)istrue.
-
close
public void close()Description copied from interface:ExtractorCloses without throwing an exception.
-