ByteBufferUtil { public static ByteBuffer merge(final ByteBuffer... dataArray) { int totalCapacity = 0; for (final ByteBuffer data : dataArray) { totalCapacity += data.capacity(); } final ByteBuffer wholeData = ByteBuffer.allocate(totalCapacity); for (final ByteBuffer data : dataArray) { wholeData.put(data); } wholeData.flip(); return wholeData; } private  ByteBufferUtil(); static int slice(final ByteBuffer data, final int maxSliceSize,
            final Slice<ByteBuffer> slice); static int sliceIfRequired(final ByteBuffer data,
            final int maxSliceSize, final Slice<ByteBuffer> slice); static ByteBuffer merge(final ByteBuffer... dataArray);  }
@Test public void testMerge() throws Exception { { final ByteBuffer webfirmframework = ByteBuffer.wrap("webfirmframework".getBytes(StandardCharsets.UTF_8)); final ByteBuffer merged = ByteBufferUtil.merge(webfirmframework); assertEquals("webfirmframework", new String(merged.array(), StandardCharsets.UTF_8)); } { final ByteBuffer webfirmframework = ByteBuffer.wrap("webfirmframework".getBytes(StandardCharsets.UTF_8)); final ByteBuffer wffweb = ByteBuffer.wrap("-wffweb".getBytes(StandardCharsets.UTF_8)); final ByteBuffer useLatestVersion = ByteBuffer.wrap("-use latest version".getBytes(StandardCharsets.UTF_8)); final ByteBuffer merged = ByteBufferUtil.merge(webfirmframework, wffweb, useLatestVersion); assertEquals("webfirmframework-wffweb-use latest version", new String(merged.array(), StandardCharsets.UTF_8)); } }