java.nio.ByteBuffer类的isDirect()方法用于判断此字节缓冲区是否为直接缓冲区。
用法:
public abstract boolean isDirect()
返回值:当且仅当此缓冲区是直接缓冲区时,此方法才返回true。
下面是说明isDirect()方法的示例:
范例1:
// Java program to demonstrate
// isDirect() method
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// defining and allocating ByteBuffer
// using allocate() method
ByteBuffer byteBuffer
= ByteBuffer.allocateDirect(4);
// check the byteBuffer
// using isDirect() method
boolean val = byteBuffer.isDirect();
// checking the condition
if (val)
System.out.println("buffer is direct");
else
System.out.println("buffer is not direct");
}
}
输出:
buffer is direct
范例2:
// Java program to demonstrate
// isDirect() method
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// defining and allocating ByteBuffer
// using allocate() method
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
// check the byteBuffer
// using isDirect() method
boolean val = byteBuffer.isDirect();
// checking the condition
if (val)
System.out.println("buffer is direct");
else
System.out.println("buffer is not direct");
}
}
输出:
buffer is not direct
参考:https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#isDirect-
相关用法
- Java Buffer isDirect()用法及代码示例
- Java ByteBuffer put()方法用法及代码示例
- Java ByteBuffer flip()用法及代码示例
- Java ByteBuffer putInt()用法及代码示例
- Java ByteBuffer clear()用法及代码示例
- Java ByteBuffer limit()用法及代码示例
- Java ByteBuffer putDouble()用法及代码示例
- Java ByteBuffer putChar()用法及代码示例
- Java ByteBuffer wrap()用法及代码示例
- Java ByteBuffer putFloat()用法及代码示例
- Java ByteBuffer putLong()用法及代码示例
- Java ByteBuffer reset()用法及代码示例
- Java ByteBuffer rewind()用法及代码示例
- Java ByteBuffer position()用法及代码示例
- Java ByteBuffer mark()用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 ByteBuffer isDirect() methods in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。