Module bus.extra

Interface Extractor

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
SevenZExtractor, StreamExtractor

public interface Extractor extends Closeable
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 Type
    Method
    Description
    void
    Closes without throwing an exception.
    default void
    extract(File targetDir)
    Extracts (decompresses) to the specified directory.
    void
    extract(File targetDir, Predicate<org.apache.commons.compress.archivers.ArchiveEntry> predicate)
    Extracts (decompresses) to the specified directory.
    default InputStream
    get(String entryName)
    Gets the input stream for a file with the specified name.
    getFirst(Predicate<org.apache.commons.compress.archivers.ArchiveEntry> predicate)
    Gets the first file stream in the compressed package that meets the specified filter requirements.
  • Method Details

    • extract

      default void extract(File targetDir)
      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. null means no filtering. Extracts when Predicate.test(Object) is true.
    • get

      default InputStream get(String entryName)
      Gets the input stream for a file with the specified name.
      Parameters:
      entryName - The entry name.
      Returns:
      The file stream, or null if the file does not exist.
    • getFirst

      InputStream getFirst(Predicate<org.apache.commons.compress.archivers.ArchiveEntry> predicate)
      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 when Predicate.test(Object) is true.
      Returns:
      The stream of the first file that meets the filter requirements, or null if no matching file is found.
    • close

      void close()
      Closes without throwing an exception.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable