Here you can find the source of read(final ByteBuffer buffer, final byte marker)
static final byte[] read(final ByteBuffer buffer, final byte marker)
//package com.java2s; /**/*from w w w . j a v a 2 s. c o m*/ * Copyright (C) 2011-2012 Barchart, Inc. <http://www.barchart.com/> * * All rights reserved. Licensed under the OSI BSD License. * * http://www.opensource.org/licenses/bsd-license.php */ import java.nio.ByteBuffer; public class Main { static final byte[] read(final ByteBuffer buffer, final byte marker) { final byte[] source = buffer.array(); final int start = buffer.position(); int index = start; while (index < source.length && source[index] != marker) { index++; } buffer.position(index + 1); final int size = index - start; final byte[] target = new byte[size]; System.arraycopy(source, start, target, 0, size); return target; } }