copy Short Buffer As Byte Buffer - Java java.nio

Java examples for java.nio:ByteBuffer Short

Description

copy Short Buffer As Byte Buffer

Demo Code


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

import java.nio.ShortBuffer;

public class Main {
    public static ByteBuffer copyShortBufferAsByteBuffer(
            ShortBuffer paramShortBuffer) {
        ByteBuffer localByteBuffer = newByteBuffer(paramShortBuffer
                .remaining() * 2);//from  ww  w  . j a v  a 2s.  c  o  m
        paramShortBuffer.mark();
        localByteBuffer.asShortBuffer().put(paramShortBuffer);
        paramShortBuffer.reset();
        localByteBuffer.rewind();
        return localByteBuffer;
    }

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

Related Tutorials