Convert remaining ByteBuffer to byte array. - Java java.nio

Java examples for java.nio:ByteBuffer Convert

Description

Convert remaining ByteBuffer to byte array.

Demo Code

/*//ww w. j  a  va 2  s .  com
 * WireSpider
 *
 * Copyright (c) 2015 kazyx
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    /**
     * Convert remaining byte buffer to byte array.
     *
     * @param buffer Source byte buffer
     * @return Remaining byte array.
     */
    public static byte[] toBytesRemaining(ByteBuffer buffer) {
        byte[] array = new byte[buffer.remaining()];
        buffer.get(array);
        return array;
    }
}

Related Tutorials