Here you can find the source of newByteArrayFromByteBuffer(ByteBuffer buf)
Parameter | Description |
---|---|
buf | source ByteBuffer |
public static byte[] newByteArrayFromByteBuffer(ByteBuffer buf)
//package com.java2s; /*/*from w w w.j a v a 2 s .com*/ * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 * (the ?License??). You may not use this work except in compliance with the License, which is * available at www.apache.org/licenses/LICENSE-2.0 * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied, as more fully set forth in the License. * * See the NOTICE file distributed with this work for information regarding copyright ownership. */ import java.nio.ByteBuffer; public class Main { /** * Creates a byte array from the given ByteBuffer, the position property of input * {@link ByteBuffer} remains unchanged. * * @param buf source ByteBuffer * @return a newly created byte array */ public static byte[] newByteArrayFromByteBuffer(ByteBuffer buf) { final int length = buf.remaining(); byte[] bytes = new byte[length]; // transfer bytes from this buffer into the given destination array buf.duplicate().get(bytes, 0, length); return bytes; } }