import java.nio.*; import java.nio.ByteBuffer; public class BufferIsDirect { public static final int size = 256; public static void main(String[] argv) throws Exception { byte[] bytes = new byte[size]; ByteBuffer bbuf = ByteBuffer.wrap(bytes); boolean isDirect = bbuf.isDirect(); if (isDirect) { System.out.println("ByteBuffer direct allocated"); } else { System.out.println("ByteBuffer not direct allocated"); } bbuf = ByteBuffer.allocate(size); isDirect = bbuf.isDirect(); if (isDirect) { System.out.println("ByteBuffer direct allocated"); } else { System.out.println("ByteBuffer not direct allocated"); } bbuf = ByteBuffer.allocateDirect(size); isDirect = bbuf.isDirect(); if (isDirect) { System.out.println("ByteBuffer direct allocated"); } else { System.out.println("ByteBuffer not direct allocated"); } } }