Package | Description |
---|---|
org.dromara.hutool.core.io.copy |
IO流拷贝相关封装相关封装
|
Modifier and Type | Class and Description |
---|---|
class |
ChannelCopier
|
class |
FileChannelCopier
FileChannel 数据拷贝封装
FileChannel#transferTo 或 FileChannel#transferFrom 的实现是平台相关的,需要确保低版本平台的兼容性
例如 android 7以下平台在使用 ZipInputStream 解压文件的过程中,
通过 FileChannel#transferFrom 传输到文件时,其返回值可能小于 totalBytes,不处理将导致文件内容缺失
// 错误写法,dstChannel.transferFrom 返回值小于 zipEntry.getSize(),导致解压后文件内容缺失
try (InputStream srcStream = zipFile.getInputStream(zipEntry);
ReadableByteChannel srcChannel = Channels.newChannel(srcStream);
FileOutputStream fos = new FileOutputStream(saveFile);
FileChannel dstChannel = fos.getChannel()) {
dstChannel.transferFrom(srcChannel, 0, zipEntry.getSize());
}
|
class |
ReaderWriterCopier
|
class |
StreamCopier
InputStream 向 OutputStream 拷贝 |
Modifier and Type | Method and Description |
---|---|
IoCopier<S,T> |
IoCopier.setFlushEveryBuffer(boolean flushEveryBuffer)
设置是否每次写出一个buffer内容就执行flush
|
Copyright © 2025. All rights reserved.