Java ByteBuffer from Byte Array readBytes(ByteBuffer buf, int length)

Here you can find the source of readBytes(ByteBuffer buf, int length)

Description

read Bytes

License

Open Source License

Declaration

public static byte[] readBytes(ByteBuffer buf, int length) 

Method Source Code

//package com.java2s;
/**//from www.j ava 2 s. c  o  m
 * Project: ${puma-common.aid}
 * <p/>
 * File Created at 2012-6-6 $Id$
 * <p/>
 * Copyright 2010 dianping.com. All rights reserved.
 * <p/>
 * This software is the confidential and proprietary information of Dianping
 * Company. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with dianping.com.
 */

import java.nio.ByteBuffer;

public class Main {
    public static byte[] readBytes(ByteBuffer buf, int length) {
        if ((buf.position() + length) <= buf.limit()) {
            byte[] r = new byte[length];
            for (int i = 0; i < length; i++) {
                r[i] = buf.get();
            }
            return r;
        }
        return null;
    }
}

Related

  1. readByteArray(ByteBuffer in)
  2. readByteArray(ByteBuffer logBuf)
  3. readByteAsInt(ByteBuffer buffer)
  4. readBytes(ByteBuffer bb, int length)
  5. readBytes(ByteBuffer bb, int length)
  6. readBytes(ByteBuffer buffer)
  7. readBytes(ByteBuffer buffer, int length)
  8. readBytes(ByteBuffer buffer, int position, int length)
  9. readBytes(final ByteBuffer bb, final int length)