copy Float Buffer - Java java.nio

Java examples for java.nio:FloatBuffer

Description

copy Float Buffer

Demo Code


//package com.java2s;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import java.nio.FloatBuffer;

public class Main {
    public static FloatBuffer copyFloatBuffer(FloatBuffer paramFloatBuffer) {
        return copyFloatBufferAsByteBuffer(paramFloatBuffer)
                .asFloatBuffer();//from ww w  .  j  a  va  2s  . co  m
    }

    public static ByteBuffer copyFloatBufferAsByteBuffer(
            FloatBuffer paramFloatBuffer) {
        ByteBuffer localByteBuffer = newByteBuffer(paramFloatBuffer
                .remaining() * 4);
        paramFloatBuffer.mark();
        localByteBuffer.asFloatBuffer().put(paramFloatBuffer);
        paramFloatBuffer.reset();
        localByteBuffer.rewind();
        return localByteBuffer;
    }

    public static ByteBuffer newByteBuffer(int paramInt) {
        ByteBuffer localByteBuffer = ByteBuffer.allocateDirect(paramInt);
        localByteBuffer.order(ByteOrder.nativeOrder());
        return localByteBuffer;
    }
}

Related Tutorials