本文整理汇总了Java中java.nio.Buffer.isDirect方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.isDirect方法的具体用法?Java Buffer.isDirect怎么用?Java Buffer.isDirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.Buffer
的用法示例。
在下文中一共展示了Buffer.isDirect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkBufferDirect
import java.nio.Buffer; //导入方法依赖的package包/类
private static void checkBufferDirect(Buffer buffer, String type) {
if (buffer == null) {
return;
}
if (!buffer.isDirect()) {
throwIAEOrLogError("buffer is not direct. Buffers created via " + type + ".allocate() or " + type + ".wrap() are not supported. " + "Use BufferUtils.create" + type + "() instead.");
} else if (buffer.remaining() == 0) {
throwIAEOrLogError("buffer has no remaining elements. Did you forget to flip()/rewind() it?");
}
}
示例2: release
import java.nio.Buffer; //导入方法依赖的package包/类
/**
* Direct {@link ByteBuffer}s are stored in system memory, and released when garbage collection occurs
* and the buffer is deemed to be unreachable, following vanilla garbage collection procedures. At that
* point, a special finalizer, "Cleaner" runs to de-allocate the system memory (and in the case of
* {@link MappedByteBuffer}s, unmap the file).
* <p/>
* However, if garbage collection does not occur, the system memory remains taken, and the {@link MappedByteBuffer}
* (if applicable) remains mapped, meaning system level operations cannot occur in other processes.
* <p/>
* This method seeks to release a direct {@link ByteBuffer} early by calling well known reflective code
* in a best-attempt fashion. In the case that this reflective code is not present, the method
* finishes with a log message, and normal Java practice takes over; i.e. the buffer is not released
* and if it's a {@link MappedByteBuffer} the file is not unmapped, until later GC occurs or the
* JVM is terminated.
*
* @param bb
* @throws NullPointerException If bb is null.
* @throws IllegalArgumentException If bb is not a "direct" {@link ByteBuffer}
*/
public static void release(Buffer bb)
{
if (bb == null)
{
throw new NullPointerException(ByteBuffer.class.getSimpleName() + " should not be null");
}
if (!bb.isDirect())
{
throw new IllegalArgumentException(bb.getClass().getName() + " is not direct.");
}
releaseStrategy.release(bb);
}