Java ByteBuffer to Byte Array getByteArray(ByteBuffer byteBuffer)

Here you can find the source of getByteArray(ByteBuffer byteBuffer)

Description

get Byte Array

License

Open Source License

Declaration

public static byte[] getByteArray(ByteBuffer byteBuffer) 

Method Source Code

//package com.java2s;
/*/*from w  w  w.  jav  a  2s .  c o  m*/
 * Copyright (c) 2007, 2011-2013 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */

import java.nio.ByteBuffer;

public class Main {
    public static byte[] getByteArray(ByteBuffer byteBuffer) {
        short length = byteBuffer.getShort();
        byte[] array = new byte[length];
        if (length != 0) {
            byteBuffer.get(array);
        }

        return array;
    }
}

Related

  1. convertToBytes(@Nonnull ByteBuffer buffer)
  2. convertVarIntByteBufferToByteArray(ByteBuffer byteBuffer)
  3. deserializeBytes(ByteBuffer buf)
  4. getByteArray(ByteBuffer buff)
  5. getByteArray(ByteBuffer byteBuffer)
  6. getByteArray(final ByteBuffer buff)
  7. getByteArrayFromBuffer(ByteBuffer byteBuf)
  8. getByteArrayFromByteBuffer(ByteBuffer content)
  9. getBytes(ByteBuffer bb)