📄 crbtmessage.java
字号:
package com.wireless.crbt.gwif.global.pub;
import java.nio.ByteBuffer;
import net.gleamynode.netty2.Message;
import net.gleamynode.netty2.MessageParseException;
public class CRBTMessage implements Message {
private String value;
/**
* 利用该方法得到字符串,该字符串是message从输入流中解析得到,提供给外界调用,主要提供给SessionListener调用
* @return String
*/
public String getValue() {
return value;
}
/**
*
* @param value String
*/
public void setValue(String value) {
this.value = value;
}
/**
* 对message接口方法的实现,message作为一个载体用来对输入流数据进行解吸并存储在自身
* @param buf ByteBuffer
* @throws MessageParseException
* @return boolean
*/
public boolean read(ByteBuffer buf) throws MessageParseException {
// don't read body if it is partially readable
if (buf.remaining() < 0) return false;
byte[] data = new byte[buf.limit() - buf.position()];
buf.get(data, 0, data.length);
value = new String(data);
return true;
}
/**
* message接口方法的实现,message作为一个载体用来将外界的数据传入输出流
* @param buf ByteBuffer
* @return boolean
*/
public boolean write(ByteBuffer buf) {
// check if there is enough space to write body
if (buf.remaining() < 0)
return false;
buf.put(value.toString().getBytes());
return true;
}
public String toString() {
// it is a good practice to create toString() method on message classes.
return "Value (" + value + ")";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -