|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.aspire.nm.component.cmppserver.filter.coder.packet.Packet
public class Packet
用于存放与协议相关的一个完整封包
JNSF并不强制要求使用此类, 但某些情况下使用此类可以减少很多工作。
Packet底层有一个ByteBuffer来存放从网络读到字节序列, 或者经过编码后即将发送到网络的字节序列,
当向网络发送封包时, ByteBuffer的数据由具体实现类的对象内部直接填充或者在编码器中填充, 也就是说底层数据由具体实现类的对象或具体编码器实现类的对象提供.
当从网络读时, ByteBuffer由解码器负责填充, 也就是说底层数据由具体的解码器实现提供.
基于ByteBuffer请参见java.nio.ByteBuffer
| 构造方法摘要 | |
|---|---|
Packet()
构造Packet对象 |
|
Packet(byte[] bytes)
用指定的字节数组构造Packet对象 |
|
Packet(ByteBuffer buffer)
用指定的ByteBuffer构造Packet对象 |
|
| 方法摘要 | |
|---|---|
protected ByteBuffer |
allocate(int capacity)
为Packet申请底层存储空间。 |
protected byte |
get()
取得一个byte(相对) |
protected ByteBuffer |
get(byte[] desc)
取得byte[] |
protected ByteBuffer |
get(byte[] dst,
int offset,
int length)
取得byte[] |
protected byte |
get(int index)
取得byte(绝对) |
ByteBuffer |
getByteBuffer()
获得底层用于存放数据的ByteBuffer, 返回的ByteBuffer是只读的 |
byte[] |
getBytes()
返回底层字节数组 |
protected char |
getChar()
取得char(相对) |
protected char |
getChar(int index)
取得char(绝对) |
protected double |
getDouble()
取得double(相对) |
protected double |
getDouble(int index)
取得double(绝对) |
protected float |
getFloat()
取得float(相对) |
protected float |
getFloat(int index)
取得float(绝对) |
protected int |
getInt()
取得int(相对) |
protected int |
getInt(int index)
取得int(绝对) |
protected long |
getLong()
取得long(相对) |
protected long |
getLong(int index)
取得long(绝对) |
protected short |
getShort()
取得short(相对) |
protected short |
getShort(int index)
取得short(绝对) |
protected String |
getString(int length)
取得指定长度的字符串 |
protected ByteBuffer |
put(byte b)
写入byte |
protected ByteBuffer |
put(byte[] src)
写入byte[] |
protected ByteBuffer |
put(byte[] src,
int offset,
int length)
写入byte[] |
protected ByteBuffer |
put(ByteBuffer src)
写入ByteBuffer |
protected ByteBuffer |
put(int index,
byte b)
写入byte到ByteBuffer指定位置 |
protected ByteBuffer |
putChar(char value)
写入char |
protected ByteBuffer |
putChar(int index,
char value)
写入char到ByteBuffer指定位置 |
protected ByteBuffer |
putDouble(double value)
写入double |
protected ByteBuffer |
putDouble(int index,
double value)
写入double到ByteBuffer指定位置 |
protected ByteBuffer |
putFloat(float value)
写入float |
protected ByteBuffer |
putFloat(int index,
float value)
写入float到ByteBuffer指定位置 |
protected ByteBuffer |
putInt(int value)
写入int |
protected ByteBuffer |
putInt(int index,
int value)
写入int到ByteBuffer指定位置 |
protected ByteBuffer |
putLong(int index,
long value)
写入long到ByteBuffer指定位置 |
protected ByteBuffer |
putLong(long value)
写入long |
protected ByteBuffer |
putShort(int index,
short value)
写入short到ByteBuffer指定位置 |
protected ByteBuffer |
putShort(short value)
写入short |
protected ByteBuffer |
putString(String value)
写入指定字串 |
protected ByteBuffer |
putString(String value,
int beginIndex,
int endIndex)
写入指定字串 |
protected ByteBuffer |
putStringLeftPad(String value,
int len)
写入指定字串的特定长度到缓冲区, 如果字串为null或者字串长度不足, 则左补\0 |
protected ByteBuffer |
putStringRightPad(String value,
int len)
写入制定字串的特定长度到缓冲区, 如果字串为null或者字串长度不足, 则右补\0 |
protected void |
setByteBuffer(ByteBuffer bytes)
填充底层ByteBuffer, 之前已有数据将被清除, 并且通过参数ByteBuffer的其他引用对对象的更改将影响底层数据。 |
protected void |
setBytes(byte[] bytes)
填充底层ByteBuffer, 之前已有数据将被清除 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public Packet()
public Packet(byte[] bytes)
bytes - 代表封包数据的字节数组public Packet(ByteBuffer buffer)
buffer - ByteBuffer| 方法详细信息 |
|---|
public byte[] getBytes()
public ByteBuffer getByteBuffer()
protected ByteBuffer allocate(int capacity)
capacity - 存储空间大小protected void setBytes(byte[] bytes)
bytes - 字节数组protected void setByteBuffer(ByteBuffer bytes)
bytes - ByteBufferprotected ByteBuffer put(byte b)
b - byte
protected ByteBuffer put(byte[] src)
src - byte[]
protected ByteBuffer put(byte[] src,
int offset,
int length)
src - byte[]offset - byte[]的起始位置length - 写入长度
protected ByteBuffer put(ByteBuffer src)
src - ByteBuffer
protected ByteBuffer put(int index,
byte b)
index - ByteBuffer中指定位置b - byte
protected ByteBuffer putChar(char value)
value - char
protected ByteBuffer putChar(int index,
char value)
index - ByteBuffer指定位置value - char
protected ByteBuffer putDouble(double value)
value - double
protected ByteBuffer putDouble(int index,
double value)
index - ByteBuffer指定位置value - double
protected ByteBuffer putFloat(float value)
value - float
protected ByteBuffer putFloat(int index,
float value)
index - ByteBuffer指定位置value - float
protected ByteBuffer putInt(int value)
value - int
protected ByteBuffer putInt(int index,
int value)
index - ByteBuffer指定位置value - int
protected ByteBuffer putLong(long value)
value - long
protected ByteBuffer putLong(int index,
long value)
index - ByteBuffer指定位置value - long
protected ByteBuffer putShort(short value)
value - short
protected ByteBuffer putShort(int index,
short value)
index - ByteBuffer指定位置value - short
protected ByteBuffer putString(String value)
value - 字符串
protected ByteBuffer putString(String value,
int beginIndex,
int endIndex)
value - 准备写入的字串beginIndex - 字串起始字符位置endIndex - 字串终止字符位置
protected ByteBuffer putStringLeftPad(String value,
int len)
value - 字符串len - 写入长度
protected ByteBuffer putStringRightPad(String value,
int len)
value - 字符串len - 写入长度
protected byte get()
protected ByteBuffer get(byte[] desc)
desc - 目的byte[]
protected ByteBuffer get(byte[] dst,
int offset,
int length)
dst - 目的byte[]offset - dst起始位置length - 读取长度
protected byte get(int index)
index - ByteBuffer绝对位置
protected char getChar()
protected char getChar(int index)
index - ByteBuffer绝对位置
protected double getDouble()
protected double getDouble(int index)
index - ByteBuffer绝对位置
protected float getFloat()
protected float getFloat(int index)
index - ByteBuffer绝对位置
protected int getInt()
protected int getInt(int index)
index - ByteBuffer绝对位置
protected long getLong()
protected long getLong(int index)
index - ByteBuffer绝对位置
protected short getShort()
protected short getShort(int index)
index - ByteBuffer绝对位置
protected String getString(int length)
length - 长度
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||