forked from KNEMC/KLALB
优化代码,性能暴涨
This commit is contained in:
@@ -16,19 +16,20 @@ import java.nio.charset.Charset;
|
||||
public class ADDLINESPacket extends KLALBPacket {
|
||||
private String lines;
|
||||
|
||||
private static final int HEADER_LENGTH=3;
|
||||
|
||||
public String getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public ADDLINESPacket(String lines) {
|
||||
super(ADDLINES);
|
||||
super(ADDLINES,HEADER_LENGTH);
|
||||
this.lines=lines;
|
||||
}
|
||||
|
||||
|
||||
public ADDLINESPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +43,7 @@ public class ADDLINESPacket extends KLALBPacket {
|
||||
@Override
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
byte[]bta=lines.getBytes(Charset.forName("UTF-8"));
|
||||
header.putChar(1,(char) bta.length);
|
||||
klalbHeader.putChar(1,(char) bta.length);
|
||||
super.writeToChannel(dto);
|
||||
dto.write(ByteBuffer.wrap(bta));
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class ADDLINESPacket extends KLALBPacket {
|
||||
@Override
|
||||
protected void readFromChannel(ReadableByteChannel din) throws IOException {
|
||||
super.readFromChannel(din);
|
||||
int lth=header.getChar(1);
|
||||
int lth=klalbHeader.getChar(1);
|
||||
byte[]b=new byte[lth];
|
||||
ByteBuffer wp= ByteBuffer.wrap(b);
|
||||
while(wp.hasRemaining()){
|
||||
@@ -61,14 +62,9 @@ public class ADDLINESPacket extends KLALBPacket {
|
||||
lines=new String(b, Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+2+lines.getBytes(Charset.forName("UTF-8")).length;
|
||||
return HEADER_LENGTH+lines.getBytes(Charset.forName("UTF-8")).length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user