mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
add buffer
This commit is contained in:
parent
f53cb2ef9d
commit
ad2bae8a3d
@ -61,6 +61,12 @@ public class ZipWriter implements Closeable {
|
||||
|
||||
private final ZipOutputStream out;
|
||||
|
||||
/**
|
||||
* 自定义缓存大小
|
||||
*/
|
||||
private int bufferSize = IoUtil.DEFAULT_BUFFER_SIZE;
|
||||
|
||||
// region ----- Constructors
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
@ -68,7 +74,7 @@ public class ZipWriter implements Closeable {
|
||||
* @param charset 编码
|
||||
*/
|
||||
public ZipWriter(final File zipFile, final Charset charset) {
|
||||
this.out = getZipOutputStream(zipFile, charset);
|
||||
this(getZipOutputStream(zipFile, charset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +84,7 @@ public class ZipWriter implements Closeable {
|
||||
* @param charset 编码
|
||||
*/
|
||||
public ZipWriter(final OutputStream out, final Charset charset) {
|
||||
this.out = ZipUtil.getZipOutputStream(out, charset);
|
||||
this(ZipUtil.getZipOutputStream(out, charset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,6 +95,18 @@ public class ZipWriter implements Closeable {
|
||||
public ZipWriter(final ZipOutputStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
// endregion
|
||||
|
||||
/**
|
||||
* 自定义压缩缓存大小,特定条件下调节性能
|
||||
*
|
||||
* @param bufferSize 缓存大小
|
||||
* @return this
|
||||
*/
|
||||
public ZipWriter setBufferSize(final int bufferSize) {
|
||||
this.bufferSize = bufferSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置压缩级别,可选1~9,-1表示默认
|
||||
@ -293,10 +311,11 @@ public class ZipWriter implements Closeable {
|
||||
*/
|
||||
private ZipWriter putEntry(final String path, final InputStream in) throws IORuntimeException {
|
||||
final ZipEntry entry = new ZipEntry(path);
|
||||
final ZipOutputStream out = this.out;
|
||||
try {
|
||||
out.putNextEntry(entry);
|
||||
if (null != in) {
|
||||
IoUtil.copy(in, out);
|
||||
IoUtil.copy(in, out, bufferSize);
|
||||
}
|
||||
out.closeEntry();
|
||||
} catch (final IOException e) {
|
||||
@ -305,7 +324,7 @@ public class ZipWriter implements Closeable {
|
||||
IoUtil.closeQuietly(in);
|
||||
}
|
||||
|
||||
IoUtil.flush(this.out);
|
||||
IoUtil.flush(out);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user