Here you can find the source of createByteBufferOnHeap(int size)
Parameter | Description |
---|---|
size | required number of ints to store. |
public static ByteBuffer createByteBufferOnHeap(int size)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { /**/* w ww. ja v a2s. c o m*/ * Create a new ByteBuffer of the specified size. * * @param size * required number of ints to store. * @return the new IntBuffer */ public static ByteBuffer createByteBufferOnHeap(int size) { ByteBuffer buf = ByteBuffer.allocate(size).order( ByteOrder.nativeOrder()); buf.clear(); return buf; } /** * Create a new ByteBuffer of an appropriate size to hold the specified * number of ints only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of bytes that need to be held by the newly created * buffer * @return the requested new IntBuffer */ public static ByteBuffer createByteBufferOnHeap(ByteBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createByteBufferOnHeap(size); return buf; } }