org.apache.mina.core.buffer包

1.buffer包结构:

 

2.核心类:IoBuffer

A byte buffer used by MINA applications.

This is a replacement for ByteBuffer. Please refer to ByteBuffer documentation for preliminary usage. MINA does not use NIO ByteBuffer directly for two reasons:

It doesn't provide useful getters and putters such as fill, get/putString, and get/putAsciiInt() enough.

It is difficult to write variable-length data due to its fixed capacity

(1)IoBuffer基于以下两个原因,取代Nio标准包中的ByteBuffer,在mina中缓存字节

(a)提供 get/putString、get/putAsciiInt()等方法来填充数据

(b)可供扩展长度数据使用

(2)基本操作

Allocation:IoBuffer buf = IoBuffer.allocate(1024, false); //false,true代表是否useDirectBuffer

AutoExpand: buf.setAutoExpand(true);

AutoShrink:自动设置buf.setAutoShrink(true),手工设置shrink()

(3)抽象类AbstractIoBuffer及代理方法IoBufferWrapper继承于IoBuffer

(4)IoBuffer分配方式:IoBufferAllocator

默认为:private static IoBufferAllocator allocator = new SimpleBufferAllocator();

可通过 :public static void setAllocator(IoBufferAllocator newAllocator)来改变这个分配方式

其中有继承于IoBufferAllocator的类有:SimpleBufferAllocator、CachedBufferAllocator

猜你喜欢

转载自cairewen.iteye.com/blog/2003477
今日推荐