### Question:
ByteBufferUtils { public static void copyBufferToStream(OutputStream out, ByteBuffer in, int offset, int length) throws IOException { if (in.hasArray()) { out.write(in.array(), in.arrayOffset() + offset, length); } else { for (int i = 0; i < length; ++i) { out.write(in.get(offset + i)); } } } private  ByteBufferUtils(); static void writeVLong(ByteBuffer out, long i); static long readVLong(ByteBuffer in); static int putCompressedInt(OutputStream out, final int value); static void putInt(OutputStream out, final int value); static void moveBufferToStream(OutputStream out, ByteBuffer in,
      int length); static void copyBufferToStream(OutputStream out, ByteBuffer in,
      int offset, int length); static int putLong(OutputStream out, final long value,
      final int fitInBytes); static int longFitsIn(final long value); static int intFitsIn(final int value); static int readCompressedInt(InputStream input); static int readCompressedInt(ByteBuffer buffer); static long readLong(InputStream in, final int fitInBytes); static long readLong(ByteBuffer in, final int fitInBytes); static void ensureSpace(ByteBuffer out, int length); static void copyFromStreamToBuffer(ByteBuffer out,
      DataInputStream in, int length); static void copyFromBufferToBuffer(ByteBuffer out,
      ByteBuffer in, int sourceOffset, int length); static int findCommonPrefix(ByteBuffer buffer, int offsetLeft,
      int offsetRight, int limit); static int findCommonPrefix(
      byte[] left, int leftOffset, int leftLength,
      byte[] right, int rightOffset, int rightLength); static boolean arePartsEqual(ByteBuffer buffer,
      int offsetLeft, int lengthLeft,
      int offsetRight, int lengthRight); static void skip(ByteBuffer buffer, int length);  }### Answer:
@Test public void testCopyToStreamWithOffset() throws IOException { ByteBuffer buffer = ByteBuffer.wrap(array); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteBufferUtils.copyBufferToStream(bos, buffer, array.length / 2, array.length / 2); byte[] returnedArray = bos.toByteArray(); for (int i = 0; i < array.length / 2; ++i) { int pos = array.length / 2 + i; assertEquals(returnedArray[i], array[pos]); } }