byte[] b=new byte[]{11,10,3,1,5,1,1,1,1,1,1,1}; IoBuffer ib=IoBuffer.wrap(b); System.out.println(ib.get()); System.out.println(ib.remaining()); System.out.println(ib.position()); boolean bt=ib.prefixedDataAvailable(1); System.out.println(bt);
返回值
11
11
1
true
一、
prefixedDataAvailable(1);
从iobuffer的position位置开始读取值1个字节的数值(byte) 作为比较 例子取得的值 是11
ib.get(). position移动1了。
取的值11 与iobuffer的hasRemain()(不会因为prefixedDataAvailable的调用remain少1的)比较 > 0返回true;
二、
prefixedDataAvailable(2);
读取2个字节的数值(short)
三、
prefixedDataAvailable(1,2)
会报
Exception in thread "main" org.apache.mina.core.buffer.BufferDataException: dataLength: 10(iobuffer 中的第二个字节)
at org.apache.mina.core.buffer.AbstractIoBuffer.prefixedDataAvailable(AbstractIoBuffer.java:2265)
at test.test1.main(test1.java:16)
第二个参数 读取的最大长度值
四、
prefixedDataAvailable(2);
其实调用的是
prefixedDataAvailable( prefixLength, Integer.MAX_VALUE )