Class ZipReader

java.lang.Object
org.miaixz.bus.core.io.compress.ZipReader
All Implemented Interfaces:
Closeable, AutoCloseable

public class ZipReader extends Object implements Closeable
Zip文件或流读取器,一般用于Zip文件解压
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ZipReader

      public ZipReader(ZipFile zipFile)
      构造
      Parameters:
      zipFile - 读取的的Zip文件
    • ZipReader

      public ZipReader(ZipInputStream zin)
      构造
      Parameters:
      zin - 读取的的Zip文件流
    • ZipReader

      public ZipReader(ZipResource resource)
      构造
      Parameters:
      resource - 读取的的Zip文件流
  • Method Details

    • of

      public static ZipReader of(File zipFile, Charset charset)
      创建ZipReader
      Parameters:
      zipFile - 生成的Zip文件
      charset - 编码
      Returns:
      ZipReader
    • of

      public static ZipReader of(InputStream in, Charset charset)
      创建ZipReader
      Parameters:
      in - Zip输入的流,一般为输入文件流
      charset - 编码
      Returns:
      ZipReader
    • setMaxSizeDiff

      public ZipReader setMaxSizeDiff(int maxSizeDiff)
      设置检查ZipBomb文件差异倍数,-1表示不检查ZipBomb
      Parameters:
      maxSizeDiff - 检查ZipBomb文件差异倍数,-1表示不检查ZipBomb
      Returns:
      this
    • get

      public InputStream get(String path)
      获取指定路径的文件流 如果是文件模式,则直接获取Entry对应的流,如果是流模式,则遍历entry后,找到对应流返回
      Parameters:
      path - 路径
      Returns:
      文件流
    • readTo

      public File readTo(File outFile) throws InternalException
      解压到指定目录中
      Parameters:
      outFile - 解压到的目录
      Returns:
      解压的目录
      Throws:
      InternalException - IO异常
    • readTo

      public File readTo(File outFile, Predicate<ZipEntry> entryFilter) throws InternalException
      解压到指定目录中
      Parameters:
      outFile - 解压到的目录
      entryFilter - 过滤器,只保留Predicate.test(Object)结果为true的文件
      Returns:
      解压的目录
      Throws:
      InternalException - IO异常
    • read

      public ZipReader read(Consumer<ZipEntry> consumer) throws InternalException
      读取并处理Zip文件中的每一个ZipEntry
      Parameters:
      consumer - ZipEntry处理器
      Returns:
      this
      Throws:
      InternalException - IO异常
    • close

      public void close() throws InternalException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      InternalException