Java ByteBuffer Copy copyByteBuffer(ByteBuffer src)

Here you can find the source of copyByteBuffer(ByteBuffer src)

Description

Make a copy of an existing buffer (src) to a new buffer (dest)

License

LGPL

Parameter

Parameter Description
src existing buffer to make a copy

Return

the new buffer copied

Declaration

public static ByteBuffer copyByteBuffer(ByteBuffer src) 

Method Source Code

//package com.java2s;
/**// w w w  .  j a  v  a2s  .c  om
 *          NativeFmodEx Project
 *
 * Want to use FMOD Ex API (www.fmod.org) in the Java language ? NativeFmodEx is made for you.
 * Copyright ? 2005-2010 J?r?me JOUVIE (Jouvieje)
 *
 * Created on 23 feb. 2005
 * @version file v1.5.0
 * @author J?r?me JOUVIE (Jouvieje)
 * @site   http://jerome.jouvie.free.fr/
 * @mail   jerome.jouvie@gmail.com
 * 
 * INTRODUCTION
 * FMOD Ex is a music and sound effects system, by Firelight Technologies Pty, Ltd.
 * More informations can be found at:
 *       http://www.fmod.org/
 * The aim of this project is to provide a java interface for this amazing sound API.
 * 
 * 
 * GNU LESSER GENERAL PUBLIC LICENSE
 * 
 * This library 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 2.1 of the License,
 * or (at your option) any later version.
 * 
 * This library 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA 
 */

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    /**
     * Make a copy of an existing buffer (src) to a new buffer (dest)
     * @param src existing buffer to make a copy
     * @return the new buffer copied
     */
    public static ByteBuffer copyByteBuffer(ByteBuffer src) {
        ByteBuffer dest = newByteBuffer(src.capacity());
        src.rewind();
        dest.put(src);
        return dest;
    }

    /**
     * Allocate a new direct buffer
     * @param nbElements size of the ByteBuffer in bytes.
     * @return new direct buffer that holds nbElements bytes.
     */
    public static ByteBuffer newByteBuffer(int nbElements) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(nbElements);
        buffer.order(ByteOrder.nativeOrder());
        return buffer;
    }
}

Related

  1. copy2Buffer(byte[] src, int srcOff, int srcLen, ByteBuffer dst, int dstOff)
  2. copyBinary(final ByteBuffer orig)
  3. copyBuffer(ByteBuffer dest, int pos1, ByteBuffer src, int len)
  4. copyBufferToStream(OutputStream out, ByteBuffer in, int offset, int length)
  5. copyByteBuffer(ByteBuffer buf)
  6. copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep)
  7. copyByteBuffer(final ByteBuffer pBuffer)
  8. copyByteBuffer(java.nio.ByteBuffer data)
  9. copyBytes(ByteBuffer bytes)