Java ByteBuffer to Byte Array toByteArray(ByteBuffer buffer)

Here you can find the source of toByteArray(ByteBuffer buffer)

Description

to Byte Array

License

Open Source License

Declaration

public static byte[] toByteArray(ByteBuffer buffer) 

Method Source Code


//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    public static byte[] toByteArray(ByteBuffer buffer) {
        return toByteArray(buffer, 0, buffer.capacity());
    }/*from w  w  w  .j a va  2  s.c  o m*/

    public static byte[] toByteArray(ByteBuffer buffer, int off, int len) {
        if (buffer.hasArray())
            if (off == 0 && len == buffer.capacity())
                return buffer.array();

        byte[] result = new byte[len];
        buffer.clear();
        buffer.position(off);
        buffer.get(result);
        return result;
    }
}

Related

  1. toArray(final ByteBuffer b)
  2. toArray(final ByteBuffer buffer)
  3. toByteArray(ByteBuffer bb)
  4. toByteArray(ByteBuffer buf)
  5. toByteArray(ByteBuffer buffer)
  6. toByteArray(ByteBuffer buffer)
  7. toByteArray(ByteBuffer buffer)
  8. toByteArray(ByteBuffer buffer, int length)
  9. toByteArray(ByteBuffer buffer, int length)