Package org.aoju.bus.core.compress
Class ZipWriter
java.lang.Object
org.aoju.bus.core.compress.ZipWriter
-
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 ZipWriterstatic ZipWriterof(OutputStream out, Charset charset) setComment(String comment) 设置注释setLevel(int level) 设置压缩级别,可选1~9,-1表示默认setMethod(int method) 设置压缩方式
-
Constructor Details
-
ZipWriter
-
ZipWriter
构造- Parameters:
out-ZipOutputStreamcharset- 编码
-
ZipWriter
-
-
Method Details
-
of
-
of
- Parameters:
out- Zip输出的流,一般为输出文件流charset- 编码- Returns:
ZipWriter
-
setLevel
-
setComment
-
setMethod
设置压缩方式- Parameters:
method- 压缩方式,支持ZipOutputStream.DEFLATED和ZipOutputStream.STORED- Returns:
- this
-
getOut
-
add
添加资源到压缩包,添加后关闭资源流- Parameters:
resources- 需要压缩的资源,资源的路径为Resource.getName()- Returns:
- this
- Throws:
InternalException- IO异常
-
add
添加文件流到压缩包,添加后关闭输入文件流 如果输入流为null,则只创建空目录- Parameters:
path- 压缩的路径,null和""表示根目录下in- 需要压缩的输入流,使用完后自动关闭,null表示加入空目录- Returns:
- this
- Throws:
InternalException- IO异常
-
add
对流中的数据加入到压缩文件 路径列表和流列表长度必须一致- Parameters:
paths- 流数据在压缩文件中的路径或文件名ins- 要压缩的源,添加完成后自动关闭流- Returns:
- 压缩文件
- Throws:
InternalException- IO异常
-
add
对文件或文件目录进行压缩- Parameters:
withSrcDir- 是否包含被打包目录,只针对压缩目录有效。若为false,则只压缩目录下的文件或目录,为true则将本目录也压缩filter- 文件过滤器,通过实现此接口,自定义要过滤的文件(过滤掉哪些文件或文件夹不加入压缩),null表示不过滤files- 要压缩的源文件或目录。如果压缩一个文件,则为该文件的全路径;如果压缩一个目录,则为该目录的顶层目录路径- Returns:
- this
- Throws:
InternalException- IO异常
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
InternalException
-