@Test public void cloneByteBuffer() { final int bufferSize = 10; ByteBuffer buf = ByteBuffer.allocate(bufferSize); for (byte i = 0; i < bufferSize; i++) { buf.put(i); } ByteBuffer bufClone = BufferUtils.cloneByteBuffer(buf); assertEquals(buf, bufClone); }
public static ByteBuffer cloneByteBuffer(ByteBuffer buf) { ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position()); if (buf.hasArray()) { ret.put(buf.array(), buf.position(), buf.limit() - buf.position()); } else { ret.put(buf); } ret.flip(); return ret; }
BufferUtils { public static ByteBuffer cloneByteBuffer(ByteBuffer buf) { ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position()); if (buf.hasArray()) { ret.put(buf.array(), buf.position(), buf.limit() - buf.position()); } else { ret.put(buf); } ret.flip(); return ret; } }
BufferUtils { public static ByteBuffer cloneByteBuffer(ByteBuffer buf) { ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position()); if (buf.hasArray()) { ret.put(buf.array(), buf.position(), buf.limit() - buf.position()); } else { ret.put(buf); } ret.flip(); return ret; } private  BufferUtils(); }
BufferUtils { public static ByteBuffer cloneByteBuffer(ByteBuffer buf) { ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position()); if (buf.hasArray()) { ret.put(buf.array(), buf.position(), buf.limit() - buf.position()); } else { ret.put(buf); } ret.flip(); return ret; } private  BufferUtils(); static int byteToInt(byte b); static synchronized void cleanDirectBuffer(ByteBuffer buffer); static ByteBuffer cloneByteBuffer(ByteBuffer buf); static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source); static void putIntByteBuffer(ByteBuffer buf, int b); static byte[] getIncreasingByteArray(int len); static byte[] getIncreasingByteArray(int start, int len); static boolean equalConstantByteArray(byte value, int len, byte[] arr); static boolean equalIncreasingByteArray(int len, byte[] arr); static boolean equalIncreasingByteArray(int start, int len, byte[] arr); static ByteBuffer getIncreasingByteBuffer(int len); static ByteBuffer getIncreasingByteBuffer(int start, int len); static boolean equalIncreasingByteBuffer(int start, int len, ByteBuffer buf); static void writeBufferToFile(String path, byte[] buffer); static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest); static int intAsUnsignedByteValue(int i); static byte[] newByteArrayFromByteBuffer(ByteBuffer buf); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position, int length); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position); }
BufferUtils { public static ByteBuffer cloneByteBuffer(ByteBuffer buf) { ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position()); if (buf.hasArray()) { ret.put(buf.array(), buf.position(), buf.limit() - buf.position()); } else { ret.put(buf); } ret.flip(); return ret; } private  BufferUtils(); static int byteToInt(byte b); static synchronized void cleanDirectBuffer(ByteBuffer buffer); static ByteBuffer cloneByteBuffer(ByteBuffer buf); static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source); static void putIntByteBuffer(ByteBuffer buf, int b); static byte[] getIncreasingByteArray(int len); static byte[] getIncreasingByteArray(int start, int len); static boolean equalConstantByteArray(byte value, int len, byte[] arr); static boolean equalIncreasingByteArray(int len, byte[] arr); static boolean equalIncreasingByteArray(int start, int len, byte[] arr); static ByteBuffer getIncreasingByteBuffer(int len); static ByteBuffer getIncreasingByteBuffer(int start, int len); static boolean equalIncreasingByteBuffer(int start, int len, ByteBuffer buf); static void writeBufferToFile(String path, byte[] buffer); static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest); static int intAsUnsignedByteValue(int i); static byte[] newByteArrayFromByteBuffer(ByteBuffer buf); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position, int length); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position);  }