Java ByteBuffer Get getAsBytes(List buffers)

Here you can find the source of getAsBytes(List buffers)

Description

Copies the contents of the buffers into a single byte[]

License

Apache License

Declaration


public static byte[] getAsBytes(List<ByteBuffer> buffers) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

import java.util.List;

public class Main {
    /**/* w ww . j av a  2  s  .  c o m*/
     * Copies the contents of the buffers into a single byte[]
     */
    //TODO: not tested
    public static byte[] getAsBytes(List<ByteBuffer> buffers) {
        //find total size
        int size = 0;
        for (ByteBuffer buffer : buffers) {
            size += buffer.remaining();
        }

        byte[] arr = new byte[size];

        int offset = 0;
        for (ByteBuffer buffer : buffers) {
            int len = buffer.remaining();
            buffer.get(arr, offset, len);
            offset += len;
        }

        return arr;
    }
}

Related

  1. getAddress(ByteBuffer buffer)
  2. getAddress(ByteBuffer buffer)
  3. getAddressFromDirectByteBuffer(ByteBuffer buffer)
  4. getArray(ByteBuffer buffer)
  5. getAsByteBuffer()
  6. getAscii(ByteBuffer bytes)
  7. getAsciiString(ByteBuffer buffer)
  8. getAsIntArray(ByteBuffer yuv, int size)
  9. getAttrs(Map fields)