Here you can find the source of toArray(final ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | Byte buffer to convert. |
public static byte[] toArray(final ByteBuffer buffer)
//package com.java2s; /* See LICENSE for licensing and NOTICE for copyright. */ import java.nio.ByteBuffer; public class Main { /**/*from ww w . ja v a 2s. co m*/ * Converts a byte buffer into a byte array. * * @param buffer Byte buffer to convert. * * @return Byte array corresponding to bytes of buffer from current position * to limit. */ public static byte[] toArray(final ByteBuffer buffer) { if (buffer.limit() == buffer.capacity()) { return buffer.array(); } final byte[] array = new byte[buffer.limit()]; buffer.position(0); buffer.get(array); return array; } }