目录
3个构造函数,方法slice,duplicate,asReadOnlyBuffer
方法ix,3个get,isDirect,isReadOnly
方法2个getXXX,2个putXXX,asXXXBuffer(char,short,int,long,float,double)
简介
package java.nio;
/**
*
* 一个读/写HeapByteBuffer。
*
*/
class HeapByteBuffer extends ByteBuffer
3个构造函数,方法slice,duplicate,asReadOnlyBuffer
// 为了提高速度,这些字段是在X-Buffer中声明的;这些声明在这里作为文档
/*
*
* protected final byte[] hb;
*
* protected final int offset;
*
*/
HeapByteBuffer(int cap, int lim) { // package-private
// ByteBuffer(int mark, int pos, int lim, int cap, byte[] hb, int offset)
super(-1, 0, lim, cap, new byte[cap], 0);
/*
* mark = -1, pos = 0, lim = lim, cap = cap
* hb = new byte[cap]; offset = 0;
*/
}
HeapByteBuffer(byte[] buf, int off, int len) { // package-private
super(-1, off, off + len, buf.length, buf, 0);
/*
* pos = off,lim = off + len,cap = buf.length
* hb = buf; offset = 0;
*/
}
protected HeapByteBuffer(byte[] buf, int mark, int pos, int lim, int cap, int off) {
super(mark, pos, lim, cap, buf, off);
/*
* hb = buf; offset = off;
*/
}
// 根据hb和其他标志位,新建一个HeapByteBuffer类型的ByteBuffer
public ByteBuffer slice() {
return new HeapByteBuffer(hb, -1, 0, this.remaining(), this.remaining(), this.position() + offset);
}
public ByteBuffer duplicate() {
return new HeapByteBuffer(hb, this.markValue(), this.position(), this.limit(), this.capacity(), offset);
}
public ByteBuffer asReadOnlyBuffer() {
// 注意:这个的构造函数是HeapByteBufferR,只读的
return new HeapByteBufferR(hb, this.markValue(), this.position(), this.limit(), this.capacity(), offset);
}