Java ByteBuffer check If a ByteBuffer is direct

Description

Java ByteBuffer check If a ByteBuffer is direct

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
    /* w  ww  .  j ava2s.c  o  m*/
    System.out.println(isDirect);

    bbuf = ByteBuffer.allocateDirect(10);
    isDirect = bbuf.isDirect(); // true

    System.out.println(isDirect);
  }
}



PreviousNext

Related