Java FloatBuffer convert to ByteBuffer

Description

Java FloatBuffer convert to ByteBuffer



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

import java.nio.FloatBuffer;

public class Main {
    public static ByteBuffer copyFloatBufferAsByteBuffer(
            FloatBuffer paramFloatBuffer) {
        ByteBuffer localByteBuffer = newByteBuffer(paramFloatBuffer
                .remaining() * 4);/*from  w w w . j a  v  a2 s  . co m*/
        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;
    }
}



PreviousNext

Related