org.apache.mina.core.buffer包

本文介绍IoBuffer如何在MINA框架中替代标准NIO ByteBuffer,并解释了其提供的额外功能,如get/putString方法及对变长数据的支持。同时涵盖了IoBuffer的基本操作、自动扩展和收缩机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值