Java ByteBuffer to Byte Array toArray(ByteBuffer buffer)

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

Description

to Array

License

Open Source License

Parameter

Parameter Description
buffer The buffer to read from.

Return

Returns the remaining bytes from the buffer copied to an array.

Declaration

public static byte[] toArray(ByteBuffer buffer) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**// w w w. j  a va  2  s .  c om
     * @param buffer The buffer to read from.
     * @return Returns the remaining bytes from the buffer copied to an array.
     */
    public static byte[] toArray(ByteBuffer buffer) {
        byte[] dst = new byte[buffer.remaining()];
        buffer.mark();
        buffer.get(dst);
        buffer.reset();
        return dst;
    }
}

Related

  1. readBytes(byte[] dest, int offset, int length, ByteBuffer buffer)
  2. readBytes(SocketChannel socketChannel, ByteBuffer byteBuffer, int length)
  3. readBytesFromByteBuffer(ByteBuffer byteBuffer)
  4. readBytesNoLength(ByteBuffer logBuf, int size)
  5. readBytesWithShortLength(ByteBuffer bb)
  6. toArray(ByteBuffer buffer)
  7. toArray(ByteBuffer buffer)
  8. toArray(ByteBuffer buffer)
  9. toArray(ByteBuffer buffer)