Methods Summary |
---|
public void | append(byte b)Appends byte to packed data.
buffer[offset++] = b;
|
public void | appendBytes(byte[] bytes)Appends given bytes to packed data.
System.arraycopy(bytes, 0, buffer, offset, bytes.length);
offset += bytes.length;
|
public void | appendInt(int value)Appends a 4-byte rpresentation of given integer value to packed data.
The value can be restored by extractInt() method.
for (int i = 0; i < 4; i++) {
buffer[offset++] = (byte)value;
value >>= 8;
}
|
public byte | extract()Extracts next byte from packed data.
return buffer[offset++];
|
public byte[] | extractBytes(int length)Extracts next requested amount of bytes from packed data.
byte[] bytes = new byte[length];
System.arraycopy(buffer, offset, bytes, 0, length);
offset += length;
return bytes;
|
public int | extractInt()Extracts integer value previously stored by appendInt() from byte
represnetation.
int value = 0;
for (int i = 0; i < 4; i++) {
value |= (buffer[offset++] & 0xff) << (8 * i);
}
return value;
|
public byte[] | release()Removes internal reference to current byte array, returning
the reference outside.
byte[] tmp = buffer;
buffer = null;
return tmp;
|
public void | reset(byte[] buffer)Resets state, setting packed data destination to given array
and current offset to 0.
offset = 0;
this.buffer = buffer;
|
public void | reset()Resets state, setting current offset to 0.
offset = 0;
|