Here you can find the source of copyByteBuffer(final ByteBuffer pBuffer)
Parameter | Description |
---|---|
pBuffer | The buffer. |
public static final ByteBuffer copyByteBuffer(final ByteBuffer pBuffer)
//package com.java2s; /**/*w ww . j a va2 s . com*/ * (C) Copyright 2007, Deft Labs. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.nio.ByteBuffer; public class Main { /** * Clone a byte buffer. This doesn't work on direct buffers. The mark isn't * passed to the new buffer. The size of the new buffer is based on the * limit and not the capacity. * @param pBuffer The buffer. * @return The new object. */ public static final ByteBuffer copyByteBuffer(final ByteBuffer pBuffer) { if (pBuffer.isDirect()) { throw new IllegalArgumentException("direct buffers not supported"); } final ByteBuffer buffer = ByteBuffer.allocate(pBuffer.limit()); buffer.order(pBuffer.order()); buffer.put(pBuffer.array()); buffer.position(pBuffer.position()); return buffer; } }