ByteBuffer

File & Network View source
ByteBuffer
public class ByteBuffer

Methods

writeByteUnsafe(int n)

Writes an unsigned byte into the buffer. You must be sure that the provided integer is in the range [0, 255].

writeShortUnsafe(int n)

Writes an unsigned short into the buffer. You must be sure that the provided integer is in the range [0, 65535].

writeByte(int n)

Writes an unsigned byte into the buffer.

writeShort(int n)

Writes an unsigned short into the buffer.

writeInt(int n)

Writes a signed integer into the buffer.

hasByte() returns bool

Returns whether at least one unread byte remains. Compares against the total byte count rather than the internal int index, so a buffer whose size is an exact multiple of 4 does not report a phantom trailing byte from the empty write buffer.

readByte() returns int

Reads a single unsigned byte from this buffer. The returned value will be in the range [0, 255]. Reading past the end yields 0; guard with hasByte(). *

readShort() returns int

Reads a single unsigned short from this buffer. The returned value will be in the range [0, 65535]. *

readInt() returns int

Reads a single signed integer from this buffer. *

resetRead()
getInt(int i) returns int
getIntCount() returns int

Number of ints backing this buffer, counting the partially filled write buffer as one. An empty buffer therefore reports 1, not 0.

size() returns int

Returns the number of bytes in the buffer. *

getByte(int i) returns int
truncate(int size)

Assures that the number of bytes is not bigger than the provided one. If it is, throws bytes from the end of the buffer away so that the number of bytes in the buffer will be exactly the provided one. Negative sizes are treated as 0.

	Should not be used when reading from the buffer.