List of usage examples for java.nio ByteBuffer rewind
public final Buffer rewind()
From source file:org.colombbus.tangara.io.ScriptHeaderHelper.java
private static ByteBuffer extractHeaderAsByteBuffer(ByteBuffer content) { moveToHeaderEnd(content);//from w w w . ja va 2 s . co m int headerLength = content.position(); content.rewind(); ByteBuffer byteHeader = ByteBuffer.allocate(headerLength); content.get(byteHeader.array()); return byteHeader; }
From source file:org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils.java
public static byte[] getBytesFromByteBuffer(ByteBuffer byteBuffer) { byteBuffer.rewind(); byte[] result = new byte[byteBuffer.limit()]; byteBuffer.get(result);//w w w .j av a2s . c o m return result; }
From source file:org.apache.hadoop.hbase.KeyValueTestUtil.java
public static List<KeyValue> rewindThenToList(final ByteBuffer bb, final boolean includesMemstoreTS, final boolean useTags) { bb.rewind(); List<KeyValue> kvs = Lists.newArrayList(); KeyValue kv = null;//from w w w. ja va 2 s.c o m while (true) { kv = KeyValueUtil.nextShallowCopy(bb, includesMemstoreTS, useTags); if (kv == null) { break; } kvs.add(kv); } return kvs; }
From source file:Main.java
public static Buffer fillBuffer(float[] array) { // Convert to floats because OpenGL doesnt work on doubles, and manually // casting each input value would take too much time. ByteBuffer bb = ByteBuffer.allocateDirect(4 * array.length); // each // float//from www . ja v a 2 s . c o m // takes 4 // bytes bb.order(ByteOrder.LITTLE_ENDIAN); for (float d : array) bb.putFloat(d); bb.rewind(); return bb; }
From source file:Main.java
public static Buffer fillBuffer(double[] array) { // Convert to floats because OpenGL doesnt work on doubles, and manually // casting each input value would take too much time. ByteBuffer bb = ByteBuffer.allocateDirect(4 * array.length); // each // float// w w w . j av a 2 s. c o m // takes 4 // bytes bb.order(ByteOrder.LITTLE_ENDIAN); for (double d : array) bb.putFloat((float) d); bb.rewind(); return bb; }
From source file:org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils.java
public static Buffer getBufferFromBytes(byte[] input) { ByteBuffer bb = ByteBuffer.wrap(input); return bb.rewind(); }
From source file:org.jboss.sepro.util.HashTool.java
public static String hashPasswordDigest(String nonce, String timestamp, String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { ByteBuffer buf = ByteBuffer.allocate(1000); buf.put(Base64.decodeBase64(nonce)); buf.put(timestamp.getBytes("UTF-8")); buf.put(password.getBytes("UTF-8")); byte[] toHash = new byte[buf.position()]; buf.rewind(); buf.get(toHash);/* w w w. j ava2 s.c om*/ return Base64.encodeBase64String(MessageDigest.getInstance("sha-1").digest(toHash)).trim(); }
From source file:experts.net.ip6.ULUA.java
/** * Convert ByteBuffer to Short List//w ww.j a va 2s . c om * * @param buf * ByteBuffer * @return Short List */ private static List<Short> toList(ByteBuffer buf) { int cap = buf.capacity() / 2; List<Short> tmp = new ArrayList<>(cap); buf.rewind(); for (int i = 0; i < cap; i++) { tmp.add(buf.getShort()); } // for return tmp; }
From source file:info.gehrels.flockDBClient.ByteHelper.java
static ByteBuffer asByteBuffer(long... destinationIds) { ByteBuffer buf = null; buf = ByteBuffer.wrap(new byte[destinationIds.length * (Long.SIZE / 8)]); buf.order(ByteOrder.LITTLE_ENDIAN); for (long destinationId : destinationIds) { buf.putLong(destinationId);//w w w . jav a2 s . c o m } buf.rewind(); return buf; }
From source file:com.liveramp.commons.util.BytesUtils.java
public static ByteBuffer byteBufferDeepCopy(ByteBuffer src, ByteBuffer dst) { if (dst == null || dst.capacity() < src.remaining()) { dst = byteBufferDeepCopy(src);// ww w.j a v a 2 s .c o m } else { dst.rewind(); dst.limit(src.remaining()); dst.put(src.slice()); dst.flip(); } return dst; }