📄 infopacket.java
字号:
package utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.Serializable;
public class InfoPacket implements Serializable{
private static final long serialVersionUID = 5883873346999033767L;
public static final int LOGIN = 1;
public static final int LOGIN_RESP = 2;
public static final int CHAT = 3;
public static final int UP = 4;
public static final int DOWN = 5;
public static final int MODIINFO=6;
public static final int AFFICHE=7;
public static final int FILE=8;
public static final int FILE_RESP=9;
private int type;
private String from=null;
private String to=null;
private String datas=null;
public InfoPacket(int type, String from, String to, String datas ) {
this.type = type;
this.from = from;
this.to = to;
this.datas =datas;
}
/**
* 解包
*/
public InfoPacket(byte[] bs) {
ByteArrayInputStream bais = new ByteArrayInputStream(bs);
DataInputStream dis = new DataInputStream(bais);
try {
this.type = dis.readInt();
this.from = dis.readUTF();
this.to = dis.readUTF();
this.datas = dis.readUTF();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 将字段转换成字节数组,即打包
*
* @return
*/
public byte[] toByteArray() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
dos.writeInt(type);
dos.writeUTF(from);
dos.writeUTF(to);
dos.writeUTF(datas);
} catch (IOException e) {
e.printStackTrace();
}
return baos.toByteArray();
}
public String getDatas() {
return datas;
}
public void setDatas(String datas) {
this.datas = datas;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -