Java examples for java.nio:ByteBuffer
Allocate ByteBuffer in flush mode.
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static void main(String[] argv) throws Exception { int capacity = 2; System.out.println(allocate(capacity)); }/* ww w. ja va2 s. co m*/ /** Allocate ByteBuffer in flush mode. * The position and limit will both be zero, indicating that the buffer is * empty and must be flipped before any data is put to it. * @param capacity capacity of the allocated ByteBuffer * @return Buffer */ public static ByteBuffer allocate(int capacity) { ByteBuffer buf = ByteBuffer.allocate(capacity); buf.limit(0); return buf; } }