Java ByteBuffer Allocate allocateTestBuffer(int capacity, boolean direct)

Here you can find the source of allocateTestBuffer(int capacity, boolean direct)

Description

allocate Test Buffer

License

Open Source License

Declaration

private static ByteBuffer allocateTestBuffer(int capacity, boolean direct) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    private static ByteBuffer allocateTestBuffer(int capacity, boolean direct) {
        ByteBuffer bb;/*w  ww  .  j ava 2  s  .c  o  m*/

        if (direct) {
            bb = ByteBuffer.allocateDirect(capacity);
        } else {
            bb = ByteBuffer.allocate(capacity);
        }

        for (int i = 0; i < capacity; i++) {
            bb.put((byte) (i & 0xff));
        }

        bb.flip();

        return bb;
    }

    private static ByteBuffer allocateTestBuffer(int capacity) {
        return allocateTestBuffer(capacity, false);
    }
}

Related

  1. allocateDoubles(final int howmany, final int SIZE)
  2. allocateFloats(final int howmany, final int SIZE)
  3. allocateInt()
  4. allocateInts(final int[] intarray, final int SIZE)
  5. allocateNativeOrderDirectBuffer(int size)
  6. fromBytes(byte[] data, boolean[] preAllocatedValues)