Java ByteBuffer Create allocateByteBuffer(int capacity)

Here you can find the source of allocateByteBuffer(int capacity)

Description

Allocate a ByteBuffer .

License

Open Source License

Parameter

Parameter Description
capacity capacity of buffer

Return

new buffer with the given capacity

Declaration

public static ByteBuffer allocateByteBuffer(int capacity) 

Method Source Code

//package com.java2s;

import java.nio.ByteBuffer;

public class Main {
    /**/*from  w ww. j  a  v a2 s.c  o  m*/
     * Minimum buffer size to use a direct buffer.
     */
    public static final int MIN_DIRECT_BUFFER_SIZE = 128;

    /**
     * Allocate a {@link ByteBuffer}.
     *
     * @param capacity capacity of buffer
     * @return new buffer with the given capacity
     */
    public static ByteBuffer allocateByteBuffer(int capacity) {
        return capacity >= MIN_DIRECT_BUFFER_SIZE ? ByteBuffer.allocateDirect(capacity)
                : ByteBuffer.allocate(capacity);
    }
}

Related

  1. allocaleByteBuffer(int capacity, boolean direct)
  2. allocateByteBuffer(boolean useDirectBuffer, int bufSize)
  3. allocateByteBuffer(final int bytes)
  4. createByteBuffer(byte... data)
  5. createByteBuffer(byte... values)
  6. createByteBuffer(byte[] data)
  7. createByteBuffer(int byteCount)