Mega Code Archive

 
Categories / Java / File Input Output
 

Determining If a ByteBuffer Is Direct

//Contents in a non-direct ByteBuffer are stored in the normal memory.  //Contents in a direct ByteBuffer are stored in some I/O device. import java.nio.ByteBuffer; public class Main {   public static void main(String[] argv) throws Exception {     ByteBuffer bbuf = ByteBuffer.wrap(new byte[10]);     boolean isDirect = bbuf.isDirect(); // false     bbuf = ByteBuffer.allocate(10);     isDirect = bbuf.isDirect(); // false     bbuf = ByteBuffer.allocateDirect(10);     isDirect = bbuf.isDirect(); // true   } }