copy Double Buffer As Byte Buffer - Java java.nio

Java examples for java.nio:ByteBuffer Double

Description

copy Double Buffer As Byte Buffer

Demo Code


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

public class Main {
    public static ByteBuffer copyDoubleBufferAsByteBuffer(
            DoubleBuffer paramDoubleBuffer) {
        ByteBuffer localByteBuffer = newByteBuffer(paramDoubleBuffer
                .remaining() * 8);//from w  w  w.  j a  v  a 2  s. com
        paramDoubleBuffer.mark();
        localByteBuffer.asDoubleBuffer().put(paramDoubleBuffer);
        paramDoubleBuffer.reset();
        localByteBuffer.rewind();
        return localByteBuffer;
    }

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

Related Tutorials