Java ByteBuffer to Byte Array toArray(ByteBuffer buffer)

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

Description

to Array

License

BSD License

Declaration

public static byte[] toArray(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
/**//from  ww  w . ja va  2s .c o  m
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 * 
 * @author The JCodec project
 * 
 */

import java.nio.ByteBuffer;

public class Main {
    public static byte[] toArray(ByteBuffer buffer) {
        byte[] result = new byte[buffer.remaining()];
        buffer.duplicate().get(result);
        return result;
    }

    public static ByteBuffer duplicate(ByteBuffer bb) {
        ByteBuffer out = ByteBuffer.allocate(bb.remaining());
        out.put(bb.duplicate());
        out.flip();
        return out;
    }
}

Related

  1. readBytesWithShortLength(ByteBuffer bb)
  2. toArray(ByteBuffer buffer)
  3. toArray(ByteBuffer buffer)
  4. toArray(ByteBuffer buffer)
  5. toArray(ByteBuffer buffer)
  6. toArray(ByteBuffer buffer)
  7. toArray(ByteBuffer buffer)
  8. toArray(ByteBuffer bytebuffer)
  9. toArray(final ByteBuffer b)