Java ByteBuffer Read read(final ByteBuffer buffer, final byte marker)

Here you can find the source of read(final ByteBuffer buffer, final byte marker)

Description

read

License

BSD License

Declaration

static final byte[] read(final ByteBuffer buffer, final byte marker) 

Method Source Code

//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;
    }
}

Related

  1. read(ByteBuffer bb, FileChannel ch)
  2. read(ByteBuffer bb, int elementWidth)
  3. read(ByteBuffer buffer)
  4. read(ByteBuffer dest, ByteBuffer src)
  5. read(ByteBuffer src, int len)
  6. read(SocketChannel p_channel, SSLEngine p_sslEngine, ByteBuffer p_inAppBuf, ByteBuffer p_inNetBuf)
  7. readableBytes(ByteBuffer buffer)
  8. readAlexString(ByteBuffer buffer)
  9. readAllLeftBytes(ByteBuffer buffer)