@Test public void testCopyCorrect() { Random r = new Random(0); ByteBuffer src = ByteBuffer.allocate(200); r.nextBytes(src.array()); src.position(77); src.limit(127); ByteBuffer dest = ByteBuffer.allocate(500); r.nextBytes(dest.array()); dest.position(133); dest.limit(450); ByteBuffers.copyTo(src, dest); assertEquals(77, src.position()); assertEquals(127, src.limit()); assertEquals(183, dest.position()); assertEquals(450, dest.limit()); dest.position(133); dest.limit(183); assertEquals(src, dest); }
public static void copyTo(ByteBuffer src, ByteBuffer dest) { if (src == null || dest == null) { return; } if (src.hasArray()) { byte[] array = src.array(); int offset = src.arrayOffset() + src.position(); int length = src.remaining(); dest.put(array, offset, length); } else { for (int i = src.position(); i < src.limit(); i++) { dest.put(src.get(i)); } } }
ByteBuffers { public static void copyTo(ByteBuffer src, ByteBuffer dest) { if (src == null || dest == null) { return; } if (src.hasArray()) { byte[] array = src.array(); int offset = src.arrayOffset() + src.position(); int length = src.remaining(); dest.put(array, offset, length); } else { for (int i = src.position(); i < src.limit(); i++) { dest.put(src.get(i)); } } } }
ByteBuffers { public static void copyTo(ByteBuffer src, ByteBuffer dest) { if (src == null || dest == null) { return; } if (src.hasArray()) { byte[] array = src.array(); int offset = src.arrayOffset() + src.position(); int length = src.remaining(); dest.put(array, offset, length); } else { for (int i = src.position(); i < src.limit(); i++) { dest.put(src.get(i)); } } }  }
ByteBuffers { public static void copyTo(ByteBuffer src, ByteBuffer dest) { if (src == null || dest == null) { return; } if (src.hasArray()) { byte[] array = src.array(); int offset = src.arrayOffset() + src.position(); int length = src.remaining(); dest.put(array, offset, length); } else { for (int i = src.position(); i < src.limit(); i++) { dest.put(src.get(i)); } } }  static void copyTo(ByteBuffer src, ByteBuffer dest); static ByteBuffer copyWithPrefix(byte prefix, ByteBuffer src); static ByteBuffer copyRemaining(ByteBuffer src); static byte[] copyRemainingBytes(ByteBuffer src); static String getString(ByteBuffer buf); }
ByteBuffers { public static void copyTo(ByteBuffer src, ByteBuffer dest) { if (src == null || dest == null) { return; } if (src.hasArray()) { byte[] array = src.array(); int offset = src.arrayOffset() + src.position(); int length = src.remaining(); dest.put(array, offset, length); } else { for (int i = src.position(); i < src.limit(); i++) { dest.put(src.get(i)); } } }  static void copyTo(ByteBuffer src, ByteBuffer dest); static ByteBuffer copyWithPrefix(byte prefix, ByteBuffer src); static ByteBuffer copyRemaining(ByteBuffer src); static byte[] copyRemainingBytes(ByteBuffer src); static String getString(ByteBuffer buf); static final Comparator<ByteBuffer> LEXICOGRAPHIC_COMPARATOR; }