forked from KNEMC/KLALB
KLALB UDP TEST
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
|
||||
public class ADDLINESPacket extends KLALBPacket {
|
||||
private String lines;
|
||||
|
||||
|
||||
public String getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public ADDLINESPacket(String lines) {
|
||||
super(ADDLINES);
|
||||
this.lines=lines;
|
||||
}
|
||||
|
||||
public ADDLINESPacket() {
|
||||
super(ADDLINES);
|
||||
}
|
||||
private int UTFlength(String str) {
|
||||
int strlen = str.length();
|
||||
int utflen = 0;
|
||||
for (int i = 0; i < strlen; i++) {
|
||||
int c = str.charAt(i);
|
||||
if ((c >= 0x0001) && (c <= 0x007F)) {
|
||||
utflen++;
|
||||
} else if (c > 0x07FF) {
|
||||
utflen += 3;
|
||||
} else {
|
||||
utflen += 2;
|
||||
}
|
||||
}
|
||||
return utflen;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ADDLINES\n"+lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+2+UTFlength(lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToStream(DataOutput dto) throws IOException {
|
||||
super.writeToStream(dto);
|
||||
dto.writeUTF(lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromStream(DataInput din) throws IOException {
|
||||
super.readFromStream(din);
|
||||
lines=din.readUTF();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user