Java ByteBuffer to Byte Array getByteArray(ByteBuffer buff)

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

Description

Create a new byte[] array and populate it with the given ByteBuffer's contents.

License

Open Source License

Parameter

Parameter Description
buff the ByteBuffer to read from

Return

a new byte array populated from the ByteBuffer

Declaration

public static byte[] getByteArray(ByteBuffer buff) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    /**/*ww  w.  j  ava2  s . c  o  m*/
     * Create a new byte[] array and populate it with the given ByteBuffer's
     * contents.
     *
     * @param buff
     *            the ByteBuffer to read from
     * @return a new byte array populated from the ByteBuffer
     */
    public static byte[] getByteArray(ByteBuffer buff) {
        if (buff == null)
            return null;
        buff.clear();
        byte[] inds = new byte[buff.limit()];
        for (int x = 0; x < inds.length; x++) {
            inds[x] = buff.get();
        }
        return inds;
    }
}

Related

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