Java ByteBuffer to Byte Array toBytes(ByteBuffer value)

Here you can find the source of toBytes(ByteBuffer value)

Description

Convert a ByteBuffer to a byte[] ByteBuffer is reset to its original state.

License

Open Source License

Declaration

static public byte[] toBytes(ByteBuffer value) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    /**/*from  ww  w .j  a  va 2s  .c om*/
     * Convert a ByteBuffer to a byte[]
     * ByteBuffer is reset to its original state.
     */
    static public byte[] toBytes(ByteBuffer value) {
        byte[] result = null;
        if (value != null && value.remaining() > 0) {
            result = new byte[value.remaining()];
            value.mark();
            value.get(result);
            value.reset();
        }
        return result;
    }
}

Related

  1. toBytes(ByteBuffer buff)
  2. toBytes(ByteBuffer buffer)
  3. toBytes(ByteBuffer buffer)
  4. toBytes(ByteBuffer buffer, int offset, int length)
  5. toBytes(ByteBuffer buffer, int startPosition)
  6. toBytes(final ByteBuffer bb)