?? stringencoder.java
字號(hào):
/**
*
* <p>Title: Smgp協(xié)議TLV結(jié)構(gòu)解析</p>
* <p>Description: 字符型編碼</p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: 福富軟件</p>
* @author chenxin
* @version 1.0 $Date 2007-07-03
*/
package ffcs.lbp.le.message.tlv;
/**
* Value encoder for string types. Operates on the java.lang.String type.
*
* @author Oran Kelly
* @version $Id: StringEncoder.java 255 2006-03-09 09:34:37Z orank $
*/
public class StringEncoder implements Encoder {
private static final String ASCII_UNSUPPORTED_MSG = "Your JVM doesn't support ASCII!";
private static final String ASCII = "US-ASCII";
/**
* Create a new StringEncoder.
*/
public StringEncoder() {
}
public void writeTo(Tag tag, Object value, byte[] b, int offset) {
try {
String s = value.toString();
int len = s.length();
byte[] b1 = s.getBytes(ASCII);
System.arraycopy(b1, 0, b, offset, len);
b[offset + len] = (byte) 0;
} catch (java.io.UnsupportedEncodingException x) {
// Java spec _requires_ US-ASCII support
throw new RuntimeException(ASCII_UNSUPPORTED_MSG);
}
}
public Object readFrom(Tag tag, byte[] b, int offset, int length) {
try {
String s = new String(b, offset, length - 1, ASCII);
return s;
} catch (java.io.UnsupportedEncodingException x) {
// Java spec _requires_ US-ASCII support
throw new RuntimeException(ASCII_UNSUPPORTED_MSG);
}
}
public int getValueLength(Tag tag, Object value) {
// 1 for the nul byte
return value.toString().length() + 1;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -