nio包buffer缓冲类


public abstract class Buffer{
// Invariants: mark <= position <= limit <= capacity
private int mark = -1;
private int position = 0;
private int limit;
private int capacity;

// Used only by direct buffers
// NOTE: hoisted here for speed in JNI GetDirectBufferAddress
long address;
}

他是一种特定的基本类
缓冲区是基本类型元素的线性有序序列,基本属性:容量,限制,位置
容量:所能包含的元素数量
限制:不能读或者写的第一个元素的索引,永远不会负,并且不会大于容量
位置:第一个能读或能写的元素索引,永远不会负,永远不会大于其限制


clear():使缓冲区做好新序列读取操作,将位置设置为0,限制设置为容量

public final Buffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}

flip:使缓冲区做好了新序列信道读取或相对 get 操作的准备:它将限制设置为当前位置,然后将该位置设置为零。

public final Buffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}

rewind:重新读取已包含数据的准备

public final Buffer rewind() {
position = 0;
mark = -1;
return this;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值