List of usage examples for java.nio ByteBuffer get
public abstract byte get();
From source file:com.inmobi.messaging.util.AuditUtil.java
private static boolean isValidVersion(ByteBuffer buffer) { byte versionFound = buffer.get(); for (byte version : versions) { if (versionFound == version) { return true; }//from w w w. j ava2 s. co m } LOG.debug("Invalid version in headers"); return false; }
From source file:Main.java
public static boolean goToPrefix(final ByteBuffer buffer) { int presudo_prefix = 0xffffffff; while (buffer.hasRemaining()) { presudo_prefix = (presudo_prefix << 8) | (buffer.get() & 0xff); if (presudo_prefix == START_PREFIX_CODE) { return true; }/*from w ww .j a va 2s. c o m*/ } return false; }
From source file:Main.java
private static int toFloat16LE(ByteBuffer buf, float[] out) { int samples = 0; while (buf.remaining() >= 2 && samples < out.length) { out[samples++] = r16 * (short) ((buf.get() & 0xff) | ((buf.get() & 0xff) << 8)); }//w w w .ja v a 2 s . co m return samples; }
From source file:Main.java
private static int toFloat16BE(ByteBuffer buf, float[] out) { int samples = 0; while (buf.remaining() >= 2 && samples < out.length) { out[samples++] = r16 * (short) (((buf.get() & 0xff) << 8) | (buf.get() & 0xff)); }//from w w w. j a v a2 s . co m return samples; }
From source file:Main.java
private static String getString(ByteBuffer buffer) { StringBuilder sb = new StringBuilder(buffer.limit()); while (buffer.remaining() > 0) { char c = (char) buffer.get(); if (c == 0) break; sb.append(c);/* w w w .ja va2 s . c o m*/ } return sb.toString(); }
From source file:Main.java
private static int toFloat24LE(ByteBuffer buf, float[] out) { int samples = 0; while (buf.remaining() >= 3 && samples < out.length) { out[samples++] = r24/*www .jav a2 s . co m*/ * ((((buf.get() & 0xff) << 8) | ((buf.get() & 0xff) << 16) | ((buf.get() & 0xff) << 24)) >> 8); } return samples; }
From source file:Main.java
private static int toFloat24BE(ByteBuffer buf, float[] out) { int samples = 0; while (buf.remaining() >= 3 && samples < out.length) { out[samples++] = r24/* w w w. j a v a 2 s. co m*/ * ((((buf.get() & 0xff) << 24) | ((buf.get() & 0xff) << 16) | ((buf.get() & 0xff) << 8)) >> 8); } return samples; }
From source file:Main.java
public static String convert(final ByteBuffer src) { src.flip();//from ww w . j a v a2s.c o m final StringBuilder buffer = new StringBuilder(src.remaining()); while (src.hasRemaining()) { buffer.append((char) (src.get() & 0xff)); } return buffer.toString(); }
From source file:Main.java
public static long readVLong(ByteBuffer bb, int len, byte firstByte) { if (len == 1) { return firstByte; }/*from w w w. ja va2 s .co m*/ long l = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = bb.get(); l = l << 8; l = l | (b & 0xFF); } return (isNegativeVNum(firstByte) ? ~l : l); }
From source file:Main.java
private static String formatBytes(byte[] data, boolean unsigned) { ByteBuffer bb = ByteBuffer.wrap(data); StringBuilder sb = new StringBuilder(bb.capacity() * 3); while (bb.remaining() > 0) { if (unsigned) { sb.append(bb.get() & 0xff); } else {/*from w w w.ja v a2 s. co m*/ sb.append(bb.get()); } sb.append(','); sb.append('\n'); } return sb.toString(); }