java.nio.Buffer.isDirect()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中java.nio.Buffer.isDirect()方法的一些代码示例,展示了Buffer.isDirect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.isDirect()方法的具体详情如下:
包路径:java.nio.Buffer
类名称:Buffer
方法名:isDirect

Buffer.isDirect介绍

[英]Returns true if this is a direct buffer.
[中]如果这是直接缓冲区,则返回true。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/*} else*/ if (usage != Usage.CpuOnly && !data.isDirect()) {
  throw new AssertionError();

代码示例来源:origin: wildfly/wildfly

/**
 * Determine whether the given buffers list is comprised solely of direct buffers or solely of heap buffers.
 *
 * @param buffers the buffers
 * @return {@code true} if all the buffers are direct, {@code false} if they are all heap buffers
 * @throws IllegalArgumentException if both direct and heap buffers were found, or if a buffer is {@code null}
 */
public static boolean isDirect(final Buffer[] buffers, final int offset, final int length) {
  boolean foundDirect = false;
  boolean foundHeap = false;
  for (int i = 0; i < length; i ++) {
    final Buffer buffer = buffers[i + offset];
    if (buffer == null) {
      throw msg.nullParameter("buffer");
    }
    if (buffer.isDirect()) {
      if (foundHeap) {
        throw msg.mixedDirectAndHeap();
      }
      foundDirect = true;
    } else {
      if (foundDirect) {
        throw msg.mixedDirectAndHeap();
      }
      foundHeap = true;
    }
  }
  return foundDirect;
}

代码示例来源:origin: robovm/robovm

int offset = 0;
int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET);
if (buffer.isDirect()) {
  src = VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
} else {

代码示例来源:origin: robovm/robovm

@MarshalsPointer(supportedCallTypes = MarshalerFlags.CALL_TYPE_BRIDGE)
public static long toNative(Buffer buffer, long flags) {
  if (buffer == null) {
    return 0L;
  }
  if (!buffer.isDirect() && !buffer.hasArray()) {
    // Non-direct buffers must be backed by an array to be supported.
    // We could have made a copy of the buffer contents and returned
    // a pointer to that but then changes made to the contents by
    // native code wouldn't be visible in the original buffer and
    // the semantics would be different depending on the type of
    // the buffer.
    throw new IllegalArgumentException("Only direct and array-backed " 
        + "java.nio.Buffers can be marshaled to pointers.");
  }
  if (buffer.isDirect()) {
    return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
  } else {
    Object array = buffer.array();
    int offset = buffer.arrayOffset();
    int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET);
    return VM.getArrayValuesAddress(array) + (offset << shift);
  }
}

代码示例来源:origin: i2p/i2p.i2p

public ByteBuffer findDeallocatableBuffer(Buffer buffer) {
  final ByteBuffer deallocatableDirectByteBuffer;
  if (buffer != null && buffer.isDirect()) {// looks for any contained

代码示例来源:origin: black.ninia/jep

@Override
protected void validate(T data) {
  if (!data.isDirect()) {
    throw new IllegalArgumentException(
        "DirectNDArray only supports direct buffers.");
  } else if (data instanceof CharBuffer) {
    throw new IllegalArgumentException(
        "DirectNDArray only supports numeric primitives, not CharBuffer");
  }
}

代码示例来源:origin: org.cojen/tupl

public static long getAddress(Buffer buf) {
  if (!buf.isDirect()) {
    throw new IllegalArgumentException("Not a direct buffer");
  }
  try {
    return UNSAFE.getLong(buf, cDirectAddressOffset);
  } catch (Exception e) {
    throw new UnsupportedOperationException(e);
  }
}

代码示例来源:origin: com.truward.tupl/tupl

public static long getAddress(Buffer buf) {
  if (!buf.isDirect()) {
    throw new IllegalArgumentException("Not a direct buffer");
  }
  try {
    return cDirectAddress.getLong(buf);
  } catch (Exception e) {
    throw new UnsupportedOperationException(e);
  }
}

代码示例来源:origin: cojen/Tupl

public static long getAddress(Buffer buf) {
  if (!buf.isDirect()) {
    throw new IllegalArgumentException("Not a direct buffer");
  }
  try {
    return UNSAFE.getLong(buf, cDirectAddressOffset);
  } catch (Exception e) {
    throw new UnsupportedOperationException(e);
  }
}

代码示例来源:origin: airlift/slice

static long bufferAddress(Buffer buffer)
{
  checkArgument(buffer.isDirect(), "buffer is not direct");
  return unsafe.getLong(buffer, ADDRESS_OFFSET);
}

代码示例来源:origin: code-disaster/steamworks4j

void checkBuffer(Buffer buffer) throws SteamException {
  if (!buffer.isDirect()) {
    throw new SteamException("Direct buffer required.");
  }
}

代码示例来源:origin: org.jogamp.jocl/jocl

static <B extends Buffer> void checkBuffer(final B directBuffer, final int flags) throws IllegalArgumentException {
  if (directBuffer != null && !directBuffer.isDirect()) {
    throw new IllegalArgumentException("buffer is not a direct buffer");
  }
  if (isHostPointerFlag(flags)) {
    throw new IllegalArgumentException("CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR can not be used with OpenGL Buffers.");
  }
}

代码示例来源:origin: gpu/JOCL

/**
 * Returns whether this Pointer is a Pointer to a direct Buffer.
 * 
 * @return Whether this pointer is a Pointer to a direct Buffer
 */
boolean isDirectBufferPointer()
{
  return getBuffer() != null && getBuffer().isDirect();
}

代码示例来源:origin: io.prestosql.cassandra/cassandra-driver

public static BufferParameterStrategy bufferParameterStrategy(Buffer buffer, ObjectParameterType.ComponentType componentType) {
  if (buffer == null || buffer.isDirect()) {
    return BufferParameterStrategy.direct(componentType);
  } else if (buffer.hasArray()) {
    return BufferParameterStrategy.heap(componentType);
  } else {
    throw new IllegalArgumentException("cannot marshal non-direct, non-array Buffer");
  }
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver

public static BufferParameterStrategy bufferParameterStrategy(Buffer buffer, ObjectParameterType.ComponentType componentType) {
  if (buffer == null || buffer.isDirect()) {
    return BufferParameterStrategy.direct(componentType);
  } else if (buffer.hasArray()) {
    return BufferParameterStrategy.heap(componentType);
  } else {
    throw new IllegalArgumentException("cannot marshal non-direct, non-array Buffer");
  }
}

代码示例来源:origin: com.cloudbees.util/jnr-unixsocket-nodep

public static BufferParameterStrategy bufferParameterStrategy(Buffer buffer, ObjectParameterType.ComponentType componentType) {
  if (buffer == null || buffer.isDirect()) {
    return BufferParameterStrategy.direct(componentType);
  } else if (buffer.hasArray()) {
    return BufferParameterStrategy.heap(componentType);
  } else {
    throw new IllegalArgumentException("cannot marshal non-direct, non-array Buffer");
  }
}

代码示例来源:origin: org.robovm/robovm-rt-common

public static long getBufferAddress(Buffer buffer) {
  if (buffer.isDirect()) {
    return VM.getLong(VM.getObjectAddress(buffer) + ADDRESS_OFFSET);
  } else {
    Object array = buffer.array();
    int offset = buffer.arrayOffset();
    int shift = getElementShift(array);
    return VM.getArrayValuesAddress(array) + (offset << shift);
  }
}

代码示例来源:origin: MobiVM/robovm

public static long getBufferAddress(Buffer buffer) {
  if (buffer.isDirect()) {
    return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
  } else {
    Object array = buffer.array();
    int offset = buffer.arrayOffset();
    int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET);
    return VM.getArrayValuesAddress(array) + (offset << shift);
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

public static long getBufferAddress(Buffer buffer) {
  if (buffer.isDirect()) {
    return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
  } else {
    Object array = buffer.array();
    int offset = buffer.arrayOffset();
    int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET);
    return VM.getArrayValuesAddress(array) + (offset << shift);
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

public static long getBufferAddress(Buffer buffer) {
  if (buffer.isDirect()) {
    return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
  } else {
    Object array = buffer.array();
    int offset = buffer.arrayOffset();
    int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET);
    return VM.getArrayValuesAddress(array) + (offset << shift);
  }
}

相关文章