Module bus.extra

Class StreamExtractor

java.lang.Object
org.miaixz.bus.extra.compress.extractor.StreamExtractor
All Implemented Interfaces:
Closeable, AutoCloseable, Extractor

public class StreamExtractor extends Object implements Extractor
Data decompressor, used to extract data from an archive package.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • StreamExtractor

      public StreamExtractor(Charset charset, File file)
      Constructor.
      Parameters:
      charset - The character encoding.
      file - The archive file.
    • StreamExtractor

      public StreamExtractor(Charset charset, String archiverName, File file)
      Constructor.
      Parameters:
      charset - The character encoding.
      archiverName - The name of the archive format, null for auto-detection.
      file - The archive file.
    • StreamExtractor

      public StreamExtractor(Charset charset, InputStream in)
      Constructor.
      Parameters:
      charset - The character encoding.
      in - The archive stream.
    • StreamExtractor

      public StreamExtractor(Charset charset, String archiverName, InputStream in)
      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: Extractor
      Gets the first file stream in the compressed package that meets the specified filter requirements.
      Specified by:
      getFirst in interface Extractor
      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.
    • 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:
      extract in interface Extractor
      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.
    • close

      public void close()
      Description copied from interface: Extractor
      Closes without throwing an exception.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Extractor