Methods Summary |
---|
byte | command()
return (byte)pkt.cmd;
|
int | id()
return id;
|
boolean | readBoolean()Read boolean represented as one byte.
byte ret = readByte();
return (ret != 0);
|
byte | readByte()Read byte represented as one bytes.
byte ret = pkt.data[inCursor];
inCursor += 1;
return ret;
|
char | readChar()Read char represented as two bytes.
int b1, b2;
b1 = pkt.data[inCursor++] & 0xff;
b2 = pkt.data[inCursor++] & 0xff;
return (char)((b1 << 8) + b2);
|
double | readDouble()Read double represented as eight bytes.
return Double.longBitsToDouble(readLong());
|
private long | readID(int size)
if (size == 8) {
return readLong();
} else { // Other sizes???
return readInt();
}
|
int | readInt()Read int represented as four bytes.
int b1,b2,b3,b4;
b1 = pkt.data[inCursor++] & 0xff;
b2 = pkt.data[inCursor++] & 0xff;
b3 = pkt.data[inCursor++] & 0xff;
b4 = pkt.data[inCursor++] & 0xff;
return ((b1 << 24) + (b2 << 16) + (b3 << 8) + b4);
|
long | readLong()Read long represented as eight bytes.
long b1,b2,b3,b4;
long b5,b6,b7,b8;
b1 = pkt.data[inCursor++] & 0xff;
b2 = pkt.data[inCursor++] & 0xff;
b3 = pkt.data[inCursor++] & 0xff;
b4 = pkt.data[inCursor++] & 0xff;
b5 = pkt.data[inCursor++] & 0xff;
b6 = pkt.data[inCursor++] & 0xff;
b7 = pkt.data[inCursor++] & 0xff;
b8 = pkt.data[inCursor++] & 0xff;
return ((b1 << 56) + (b2 << 48) + (b3 << 40) + (b4 << 32)
+ (b5 << 24) + (b6 << 16) + (b7 << 8) + b8);
|
short | readShort()Read short represented as two bytes.
int b1, b2;
b1 = pkt.data[inCursor++] & 0xff;
b2 = pkt.data[inCursor++] & 0xff;
return (short)((b1 << 8) + b2);
|
java.lang.String | readString()Read string represented as four byte length followed by
characters of the string.
String ret;
int len = readInt();
try {
ret = new String(pkt.data, inCursor, len, "UTF8");
} catch(IndexOutOfBoundsException e ) {
System.err.println(e);
ret = "IndexOutOfBoundsExceptions";
} catch(java.io.UnsupportedEncodingException e) {
System.err.println(e);
ret = "Conversion error!";
}
inCursor += len;
return ret;
|
void | send()
if (!isCommitted) {
pkt.data = dataStream.toByteArray();
try {
proxy.send(pkt);
} catch (IOException e) {
}
isCommitted = true;
}
|
int | skipBytes(int n)
inCursor += n;
return n;
|
void | waitForReply()
if (!isCommitted) {
throw new Exception("waitForReply without send");
}
proxy.waitForReply(pkt);
if (pkt.errorCode != Packet.ReplyNoError) {
throw new Exception(String.valueOf(pkt.errorCode));
}
|
void | writeBoolean(boolean data)
if(data) {
dataStream.write( 1 );
} else {
dataStream.write( 0 );
}
|
void | writeByte(byte data)
dataStream.write( data );
|
void | writeByteArray(byte[] data)
dataStream.write(data, 0, data.length);
|
void | writeChar(char data)
dataStream.write( (byte)((data >>> 8) & 0xFF) );
dataStream.write( (byte)((data >>> 0) & 0xFF) );
|
void | writeDouble(double data)
writeLong(Double.doubleToLongBits(data));
|
void | writeFloat(float data)
writeInt(Float.floatToIntBits(data));
|
void | writeID(int size, long data)
if (size == 8) {
writeLong(data);
} else {
writeInt((int)data);
}
|
void | writeInt(int data)
dataStream.write( (byte)((data >>> 24) & 0xFF) );
dataStream.write( (byte)((data >>> 16) & 0xFF) );
dataStream.write( (byte)((data >>> 8) & 0xFF) );
dataStream.write( (byte)((data >>> 0) & 0xFF) );
|
void | writeLong(long data)
dataStream.write( (byte)((data >>> 56) & 0xFF) );
dataStream.write( (byte)((data >>> 48) & 0xFF) );
dataStream.write( (byte)((data >>> 40) & 0xFF) );
dataStream.write( (byte)((data >>> 32) & 0xFF) );
dataStream.write( (byte)((data >>> 24) & 0xFF) );
dataStream.write( (byte)((data >>> 16) & 0xFF) );
dataStream.write( (byte)((data >>> 8) & 0xFF) );
dataStream.write( (byte)((data >>> 0) & 0xFF) );
|
void | writeShort(short data)
dataStream.write( (byte)((data >>> 8) & 0xFF) );
dataStream.write( (byte)((data >>> 0) & 0xFF) );
|
void | writeString(java.lang.String string)
try {
byte[] stringBytes = string.getBytes("UTF8");
writeInt(stringBytes.length);
writeByteArray(stringBytes);
} catch (java.io.UnsupportedEncodingException e) {
throw new RuntimeException("Cannot convert string to UTF8 bytes");
}
|