List of utility methods to do ByteBuffer Read
void | readFully(final FileChannel src, final ByteBuffer dst, final long position) read Fully while (dst.remaining() > 0) { if (-1 == src.read(dst, position + dst.position())) { throw new EOFException(); |
float | readHealthFloat16(ByteBuffer data) Reads a decimal value as a IEEE-11073 16-bits float byte b0 = data.get(); byte b1 = data.get(); int mantissa = unsignedToSigned((b0 & 0xFF) + ((b1 & 0x0F) << 8), 12); int exponent = unsignedToSigned((b1 & 0xFF) >> 4, 4); return (float) (mantissa * Math.pow(10, exponent)); |
String | readHexString(ByteBuffer buffer, int nrBytes) read Hex String byte[] bytes = new byte[nrBytes]; for (int i = bytes.length - 1; i >= 0; i--) { bytes[i] = buffer.get(); return toHexString(bytes); |
String | readIso639(ByteBuffer bb) read Iso int bits = readUInt16(bb); StringBuilder result = new StringBuilder(); for (int i = 0; i < 3; i++) { int c = (bits >> (2 - i) * 5) & 0x1f; result.append((char) (c + 0x60)); return result.toString(); |
void | readKatakana(ByteBuffer b, char s[], int off, int len) read Katakana while (off < len) { s[off++] = (char) (0x30A0 + (b.get() & 0xff)); |
int | readLen(ByteBuffer dup, int nls) read Len switch (nls) { case 1: return dup.get() & 0xff; case 2: return dup.getShort() & 0xffff; case 3: return ((dup.getShort() & 0xffff) << 8) | (dup.get() & 0xff); case 4: ... |
long | readLink(ByteBuffer bb) Read a 64-bit signed integer from the byte buffer, used as byte position within the file. byte[] data = new byte[8]; bb.get(data); long l1 = (((long) data[0] & 0xff) << 0) | (((long) data[1] & 0xff) << 8) | (((long) data[2] & 0xff) << 16) | (((long) data[3] & 0xff) << 24); long l2 = (((long) data[4] & 0xff) << 0) | (((long) data[5] & 0xff) << 8) | (((long) data[6] & 0xff) << 16) | (((long) data[7] & 0xff) << 24); return (l1 << 0) | (l2 << 32); |
long | readLink(ByteBuffer bb) read Link return ((long) bb.getInt() & 0xffffffffL); |
int | readNewLine(ByteBuffer buf) read New Line char ch; int num = 0; while (buf.remaining() > 0) { ch = (char) buf.get(); num++; if (ch == '\n') break; return num; |
String | readNullTerminatedString(ByteBuffer buf) read Null Terminated String return readNullTerminatedString(buf, UTF_8);
|