Android ByteBuffer Create setupByteBuffer(ByteBuffer preBuffer, byte[] array)

Here you can find the source of setupByteBuffer(ByteBuffer preBuffer, byte[] array)

Description

setup Byte Buffer

License

Open Source License

Declaration

public static ByteBuffer setupByteBuffer(ByteBuffer preBuffer,
            byte[] array) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static ByteBuffer setupByteBuffer(ByteBuffer preBuffer,
            byte[] array) {

        if (preBuffer == null || preBuffer.capacity() < array.length) {
            preBuffer = createByteBuffer(array.length * 2);
        } else {/*ww w  .j a  va 2 s . c  o m*/
            preBuffer.clear();
        }
        preBuffer.put(array);
        preBuffer.position(0);
        return preBuffer;
    }

    public static ByteBuffer createByteBuffer(int count) {
        ByteBuffer data = ByteBuffer.allocateDirect(count * 4);
        data.order(ByteOrder.nativeOrder());
        return data;
    }
}

Related

  1. list2ByteBuffer(List list)
  2. makeByteBuffer(byte[] arr)
  3. makeByteBuffer(int size)
  4. newByteBuffer(int numBytes)
  5. newByteBuffer(int paramInt)
  6. renewBuffer(ByteBuffer buf)
  7. allocateAudioBuffer(int size)
  8. makeByteBuffer(byte[] array)
  9. ConvToByteBuffer(byte buf[])