?? businessouthelper.java
字號:
package com.soft.QQ;
import java.nio.*;
import java.io.*;
import static com.soft.QQ.Config.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: soft136</p>
*
* @author Michael
* @version 1.0
*/
public class BusinessOutHelper {
private ByteBuffer bb = null;
private int length = 0;
private int pos;
public BusinessOutHelper(int allocatesize,int i) {
bb = ByteBuffer.allocate(allocatesize);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.position(0);
initHead(allocatesize,i);//初始化包頭
}
private void initHead(int allocatesize,int i) {
bb.putInt(PROTOCOL_UDP);
if(i==1){
bb.putInt(BUSINESS_SIMPLEMESSAGE);
}else if(i==2){
bb.putInt(BUSINESS_USERINFO);
}else if(i==3){
bb.putInt(BUSINESS_LISTINFO);
}
bb.putInt(PROTOCOL_VERSION);
bb.putInt(SOFT_VERSION);
pos = bb.position();
bb.putInt(length);
bb.putLong(Config.getSerialNo());
}
public void writeString(String input, int length) throws
IOException {
int i = 0;
int strPos = 0;
byte[] buf = null;
try {
buf = input.getBytes("GBK");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
int strLen = buf.length;
while (i < length) {
byte ch = (strPos < strLen ? buf[strPos++] : 0);
bb.put(ch);
i++;
}
}
public byte[] getBytes() throws IOException {
if (bb.hasArray()) {
length = bb.position();
bb.position(pos);
bb.putInt(length);
bb.position(length);
return bb.array();
} else {
return null;
}
}
public String getString(int length) throws IOException {
byte[] buf = new byte[length];
for (int i = 0; i < length; i++) {
buf[i] = bb.get();
}
return new String(buf, "GBK").trim();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -