Java examples for java.nio:ByteBuffer
make ByteBuffer
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static void main(String[] argv) throws Exception { byte[] arr = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(makeByteBuffer(arr)); }//from w ww. j a va 2s. c o m public static ByteBuffer makeByteBuffer(byte[] arr) { ByteBuffer bb = ByteBuffer.allocateDirect(arr.length); bb.order(ByteOrder.nativeOrder()); bb.put(arr); bb.position(0); return bb; } public static ByteBuffer makeByteBuffer(int size) { ByteBuffer bb = ByteBuffer.allocateDirect(size); bb.position(0); return bb; } }