Package com.luna.common.file.compress
Class ZipWriter
java.lang.Object
com.luna.common.file.compress.ZipWriter
- All Implemented Interfaces:
Closeable,AutoCloseable
Zip生成封装
- Since:
- 5.7.8
- Author:
- looly
-
Constructor Summary
ConstructorsConstructorDescription构造ZipWriter(OutputStream out, Charset charset) 构造ZipWriter(ZipOutputStream out) 构造 -
Method Summary
Modifier and TypeMethodDescriptionadd(boolean withSrcDir, FileFilter filter, File... files) 对文件或文件目录进行压缩add(String[] paths, InputStream[] ins) 对流中的数据加入到压缩文件
路径列表和流列表长度必须一致add(String path, InputStream in) 添加文件流到压缩包,添加后关闭输入文件流
如果输入流为null,则只创建空目录voidclose()getOut()获取原始的ZipOutputStreamstatic ZipWriter创建ZipWriterstatic ZipWriterof(OutputStream out, Charset charset) 创建ZipWritersetComment(String comment) 设置注释setLevel(int level) 设置压缩级别,可选1~9,-1表示默认
-
Constructor Details
-
ZipWriter
构造- Parameters:
zipFile- 生成的Zip文件charset- 编码
-
ZipWriter
构造- Parameters:
out-ZipOutputStreamcharset- 编码
-
ZipWriter
构造- Parameters:
out-ZipOutputStream
-
-
Method Details
-
of
创建ZipWriter- Parameters:
zipFile- 生成的Zip文件charset- 编码- Returns:
- ZipWriter
-
of
创建ZipWriter- Parameters:
out- Zip输出的流,一般为输出文件流charset- 编码- Returns:
- ZipWriter
-
setLevel
设置压缩级别,可选1~9,-1表示默认- Parameters:
level- 压缩级别- Returns:
- this
-
setComment
设置注释- Parameters:
comment- 注释- Returns:
- this
-
getOut
获取原始的ZipOutputStream- Returns:
ZipOutputStream
-
add
对文件或文件目录进行压缩- Parameters:
withSrcDir- 是否包含被打包目录,只针对压缩目录有效。若为false,则只压缩目录下的文件或目录,为true则将本目录也压缩filter- 文件过滤器,通过实现此接口,自定义要过滤的文件(过滤掉哪些文件或文件夹不加入压缩),null表示不过滤files- 要压缩的源文件或目录。如果压缩一个文件,则为该文件的全路径;如果压缩一个目录,则为该目录的顶层目录路径- Returns:
- this
- Throws:
IOException- IO异常- Since:
- 5.1.1
-
add
添加文件流到压缩包,添加后关闭输入文件流
如果输入流为null,则只创建空目录- Parameters:
path- 压缩的路径,null和""表示根目录下in- 需要压缩的输入流,使用完后自动关闭,null表示加入空目录- Returns:
- this
- Throws:
IOException- IO异常
-
add
对流中的数据加入到压缩文件
路径列表和流列表长度必须一致- Parameters:
paths- 流数据在压缩文件中的路径或文件名ins- 要压缩的源,添加完成后自动关闭流- Returns:
- 压缩文件
- Throws:
IOException- IO异常- Since:
- 5.8.0
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-