Here you can find the source of toArray(ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | the buffer to get the array from |
public static byte[] toArray(ByteBuffer buffer)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.nio.ByteBuffer; import java.util.Arrays; public class Main { /**// w w w. j ava2 s . c om * Get the byte array out of a ByteBuffer. * * @param buffer the buffer to get the array from * @return the byte buffer array */ public static byte[] toArray(ByteBuffer buffer) { if (buffer.hasArray()) { byte[] array = buffer.array(); int from = buffer.arrayOffset() + buffer.position(); return Arrays.copyOfRange(array, from, from + buffer.remaining()); } else { byte[] to = new byte[buffer.remaining()]; buffer.slice().get(to); return to; } } }