- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
SevenZExtractor,StreamExtractor
Archive data unpacking wrapper, used to unpack packages such as zip, tar, etc., into files.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes without throwing an exception.default voidExtracts (decompresses) to the specified directory.voidExtracts (decompresses) to the specified directory.default InputStreamGets the input stream for a file with the specified name.Gets the first file stream in the compressed package that meets the specified filter requirements.
-
Method Details
-
extract
Extracts (decompresses) to the specified directory. The stream is automatically closed after completion. This method can only be called once.- Parameters:
targetDir- The target directory.
-
extract
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.- Parameters:
targetDir- The target directory.predicate- A filter for extracted files, used to specify which files to extract.nullmeans no filtering. Extracts whenPredicate.test(Object)istrue.
-
get
Gets the input stream for a file with the specified name.- Parameters:
entryName- The entry name.- Returns:
- The file stream, or
nullif the file does not exist.
-
getFirst
Gets the first file stream in the compressed package that meets the specified filter requirements.- 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.
-
close
void close()Closes without throwing an exception.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-