List of utility methods to do ByteBuffer Get
int | getMediumInt(ByteBuffer buffer) get Medium Int return (buffer.get() & 0xFF) << 16 | (buffer.get() & 0xFF) << 8 | buffer.get() & 0xFF;
|
int | getModularShort(ByteBuffer bb) Read a int value (the size of a modular short) from a ByteBuffer Vector shorts = new Vector(); bb.order(ByteOrder.BIG_ENDIAN); short shortt = bb.getShort(); int size = 0; while ((shortt & 0x80) > 0) { shorts.add(new Short(shortt)); shortt = bb.getShort(); shorts.add(new Short(shortt)); for (int i = 0; i < shorts.size(); i++) { shortt = ((Short) shorts.get(i)).shortValue(); shorts.set(i, new Integer(((shortt & 0xff00) >> 8) | ((shortt & 0xff) << 8))); int slen = shorts.size(); if (slen == 1) { size = (((Integer) shorts.get(0)).intValue()) & 0x7fff; } else if (slen == 2) { int tmp = ((Integer) shorts.get(0)).intValue(); shorts.set(0, shorts.get(1)); shorts.set(1, new Integer(tmp)); size = (((((Integer) shorts.get(0)).intValue()) & 0x7fff) << 15) | (((((Integer) shorts.get(1)).intValue()) & 0x7fff)); } else { System.out.println("Unexpected array length: " + slen); return size; |
String[] | getMultiString(ByteBuffer bb, boolean wideChar) get Multi String ArrayList strs = new ArrayList(); StringBuilder sb = new StringBuilder(); while (bb.hasRemaining()) { char c = wideChar ? bb.getChar() : (char) bb.get(); if (c == 0) { if (sb.length() == 0) { break; } else { ... |
int | getNaluStartLength(ByteBuffer buffer) get Nalu Start Length if (buffer.remaining() <= 4) { return 0; if (buffer.get() != 0x00) { return 0; byte ch = buffer.get(); if (ch == 0x01) { ... |
int | getNextTagNum(ByteBuffer message) Gets the next tag. StringBuilder builder = new StringBuilder(10); int b; message.mark(); while (message.hasRemaining()) { if ((b = message.get()) == ((int) '=')) { break; } else { builder.append((char) b); ... |
String | getNTString(ByteBuffer buffer) Parses next null-terminated string. StringBuilder result = new StringBuilder(); while (buffer.remaining() > 0) { char c = (char) buffer.get(); if (c == '\0') break; result.append(c); return result.toString(); ... |
byte[] | getNullTerminatedByte(ByteBuffer buffer) get Null Terminated Byte int pos = buffer.position(); byte[] array = buffer.array(); int endPos = array.length - 1; for (int i = pos; i < array.length; i++) { if (NULL_TERMINATED_STRING_DELIMITER == array[i]) { endPos = i; break; byte[] vBuf = new byte[endPos - pos]; buffer.get(vBuf); buffer.position(buffer.position() + 1); return vBuf; |
int | getNumeric(java.nio.ByteBuffer buffer, int len) get Numeric String s = ""; if (null != buffer && buffer.remaining() >= len) { byte[] dest = new byte[len]; buffer.get(dest, 0, len); s = new String(dest); return Integer.parseInt(s); |
Object | getObject(ByteBuffer buffer) Reads a Object (Serializable) from a ByteBuffer. int length = buffer.getInt(); byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { bytes[i] = buffer.get(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); Object o = null; try (ObjectInputStream oin = new ObjectInputStream(bis)) { ... |
Object | getObject(ByteBuffer byteBuffer) get Object boolean nonNull = byteBuffer.get() == TRUE; if (nonNull) { byte[] array = getByteArray(byteBuffer); ByteArrayInputStream bais = new ByteArrayInputStream(array); ObjectInputStream stream = new ObjectInputStream(bais); return stream.readObject(); return null; ... |