Home Tutorial Java Corejava Nio Use of isDirect() method of intBuffer class in java.

 
 

Use of isDirect() method of intBuffer class in java.
Posted on: August 4, 2010 at 12:00 AM
Advertisement
In this tutorial you will see the use of isDirect() method of intBuffer class in java.

Use of isDirect() method of intBuffer class in java.

In this tutorial, we will check int buffer is direct or not.

IntBuffer API.

The java.nio.IntBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
abstract boolean isDirect() The isDirect() method tells whether this associated buffer is direct or not.
static IntBuffer wrap(int[] array)  The wrap(...) method create a int buffer by wrapping  the associated int array. 

Code

import java.nio.*;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

public class IntIsDirect {
  public static void main(String[] argv){
ByteBuffer b = ByteBuffer.allocateDirect(512);
    IntBuffer i = b.asIntBuffer();
    if (i.isDirect()) {
   System.out.println("int buffer is direct.");
    else {
System.out.println("int buffer is not direct.");
    }
    int[] array = new int[] {1,2,3,4,5};
    IntBuffer intBuf = IntBuffer.wrap(array);
    if (intBuf.isDirect()) {
   System.out.println("int buffer is direct.");
    else {
System.out.println("int buffer is not direct.");
    }
  }
}

Output

C:\>java IntIsDirect
int buffer is direct.
int buffer is not direct.
Advertisement

Related Tags for Use of isDirect() method of intBuffer class in java.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 4, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com