📄 encoder.java
字号:
package projectsmpp;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.util.Date;// Referenced classes of package projectsmpp// coder, encoderExceptionpublic class Encoder extends Coder//活动编码{ public void int16(short word0)//增加一个16位整数 { if(len + 2 > size) increase(2); bytes[len] = (byte)(word0 >>> 8 & 0xff); len++; bytes[len] = (byte)(word0 & 0xff); len++; } public void int16(byte byte0) { int16(byte0); } public void int16(int i) { int16((short)i); } public void UTC(Date date)//将日期转换为字符串 throws encoderException { try { if(date == null) { int8(0); return; } int i = date.getTimezoneOffset(); String s1; if(i <= 0) s1 = s2c((Math.abs(i) + 1) / 15) + "+"; else s1 = s2c((i + 1) / 15) + "-"; String s = s2c(date.getYear()) + s2c(date.getMonth() + 1) + s2c(date.getDate()) + s2c(date.getHours()) + s2c(date.getMinutes()) + s2c(date.getSeconds()) + (int)((date.getTime() % 1000L) / 100L) + s1; asciiz(s, 16); return; } catch(Exception exception) { throw new encoderException(exception + "time."); } } public void int8(byte byte0)//增加一个字符 { if(len + 1 > size) increase(1); bytes[len] = byte0; len++; } public void int8(short word0) { int8((byte)word0); } public void int8(int i) { int8((byte)i); } public byte[] getBytes()//取得数组 { byte abyte0[] = new byte[len]; for(int i = 0; i < len; i++) abyte0[i] = bytes[i]; return abyte0; } public void int32(int i)//增加一个32位整数 { if(len + 4 > size) increase(4); bytes[len] = (byte)(i >>> 24 & 0xff); len++; bytes[len] = (byte)(i >>> 16 & 0xff); len++; bytes[len] = (byte)(i >>> 8 & 0xff); len++; bytes[len] = (byte)(i & 0xff); len++; } public void int32(short word0) { int32(word0); } public void int32(byte byte0) { int32(byte0); } private static String s2c(int i)//将整数规范到100以内 { int j = i % 100; if(j < 10) return "0" + j; else return "" + j; } public Encoder(int i) { super(i); } public Encoder() { super(0); } public void asciiz(String s, int i)//增加字符 throws encoderException { int j = s.length(); if(j > i) throw new encoderException("toolong.string."); if(len + j + 1 > size) increase(j + 1); for(int k = 0; k < j; k++) { bytes[len] = (byte)(s.charAt(k) & 0xff); len++; } bytes[len] = 0; len++; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -