概述
一个字节缓冲区。可以由以下三种方式创建。
- 分配一个新的byte array,在它的基础上创建;
- 分配一个新的memory block,在它的基础上创建;
- 包含一个已存在的byte array。
公共方法
- public static ByteBuffer allocate (int capacity)
在一个新分配的byte array上创建一个byte buffer。capacity是容量。 - public static ByteBuffer allocateDirect (int capacity)
在一个新分配的memory block上创建一个byte buffer。capacity是容量。 - public final byte[] array ()
返回buffer所依赖的byte array。 - public final int arrayOffset ()
返回buffer所依赖的byte array的偏移量。 - public abstract ????Buffer asCharBuffer ()/asDoubleBuffer ()/asFloatBuffer ()/asIntBuffer ()/asLongBuffer ()/asShortBuffer ()
返回一个???? buffer,它是建立在包含内容的byte buffer上的。 - public abstract ByteBuffer compact ()
整理byte buffer。包含的bytes将被移动到buffer的头部,从0位开始。position被设置为remaining();limit被设置为capacity;mark被清空。 - public int compareTo (ByteBuffer otherBuffer)
比较两个buffer包含的bytes。当这个buffer比otherBuffer小时返回值是负数。 - public abstract ByteBuffer duplicate ()
复制。 - public ByteBuffer get (byte[] dst, int dstOffset, int byteCount)/public ByteBuffer put (byte[] src, int srcOffset, int byteCount)
从偏移位置(offset)读取/写入一定数量(byteCount)的bytes到指定的byte array(dst)。 - public abstract byte get (int index)
返回指定位置(index)的字节。 - public abstract char get/putChar ()/getDouble ()/getFloat ()/getInt ()/getLong ()/getShort ()
。。。。。。 - public void filp()
翻转。由读模式变为写模式。 - public booleans hasremaining()
判断buffer是否包含bytes。