写文件 Region

举报
满心 发表于 2021/03/09 09:47:57 2021/03/09
【摘要】 从这里我们可以看出 netty 也调用了 FileChannelDe tansferTo 方法:public class DefaultFileRegion extends AbstractReferenceCounted implements FileRegion { private FileChannel file; public long transferTo(Writable...

从这里我们可以看出 netty 也调用了 FileChannelDe tansferTo 方法:

public class DefaultFileRegion extends AbstractReferenceCounted implements FileRegion {   
private FileChannel file;

public long transferTo(WritableByteChannel target, long position) throws IOException {
long count = this.count - position;

if (count >= 0L && position >= 0L) {

if (count == 0L) {

return 0L;

} else if (this.refCnt() == 0) {

throw new IllegalReferenceCountException(0);

} else {

this.open();

long written = this.file.transferTo(this.position + position, count, target);

if (written > 0L) {

this.transferred += written;

} else if (written == 0L) {

validate(this, position);

}


return written;

}
} else {
throw new IllegalArgumentException("position out of range: " + position + " (expected: 0 - " + (this.count - 1L) + ')');
} } ...}
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。