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

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

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

Buffer.hasArray介绍

[英]Returns true if array and arrayOffset won't throw. This method does not return true for buffers not backed by arrays because the other methods would throw UnsupportedOperationException, nor does it return true for buffers backed by read-only arrays, because the other methods would throw ReadOnlyBufferException.
[中]如果array和arrayOffset不抛出,则返回true。对于不受数组支持的缓冲区,此方法不会返回true,因为其他方法将引发UnsupportedOperationException;对于受只读数组支持的缓冲区,此方法也不会返回true,因为其他方法将引发ReadOnlyBufferException。

代码示例

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

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

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

/**
 * Checks whether the Buffer is backed by a simple array. In java, a Buffer is an abstraction that
 * can represent various data, from data on disk all the way to native Java arrays. Like all
 * abstractions, a Buffer might carry a performance penalty. Thus, we sometimes check whether the
 * Buffer is simply a wrapper around a Java array. In these instances, it might be best, from a
 * performance point of view, to access the underlying array (using the array()) method.
 * @param b the provided Buffer
 * @return whether the Buffer is backed by a simple array
 */
protected static boolean isBackedBySimpleArray(Buffer b) {
 return b.hasArray() && (b.arrayOffset() == 0);
}

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

/**
   * Returns the offset in bytes from the start of the underlying
   * Java array object containing the data of the given Buffer to
   * the actual start of the data. The start of the data takes into
   * account the Buffer's current position. This method is only
   * meaningful if getBaseArray() returns non-null.
   *
   * @param b the Buffer to be queried
   * @return the data offset in bytes to the start of this Buffer's data
   */
  static int getBaseArrayOffset(Buffer b) {
    return b.hasArray() ? ((b.arrayOffset() + b.position) << b._elementSizeShift) : 0;
  }
}

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

public static int[] getIntArrayFromBuffer(Buffer buffer) {
  int[] array = new int[0];
  if (buffer != null) {
    if (buffer.hasArray()) {
      array = (int[]) buffer.array();
    } else {
      buffer.rewind();
      array = new int[buffer.capacity()];
      if (buffer instanceof IntBuffer) {
        ((IntBuffer) buffer).get(array);
      } else if (buffer instanceof ShortBuffer) {
        int count = 0;
        while (buffer.hasRemaining()) {
          array[count] = (int) (((ShortBuffer) buffer).get());
          ++count;
        }
      }
    }
  }
  return array;
}

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

/**
   * Creates an int array from the provided {@link IntBuffer} or {@link ShortBuffer}.
   * 
   * @param buffer {@link Buffer} the data source. Should be either a {@link IntBuffer} 
   * or {@link ShortBuffer}.
   * @return int array containing the data of the buffer.
   */
  public static int[] getIntArrayFromBuffer(Buffer buffer) {
    int[] array = null;
    if (buffer.hasArray()) {
      array = (int[]) buffer.array();
    } else {
      buffer.rewind();
      array = new int[buffer.capacity()];
      if (buffer instanceof IntBuffer) {
        ((IntBuffer) buffer).get(array);
      } else if (buffer instanceof ShortBuffer) {
        int count = 0;
        while (buffer.hasRemaining()) {
          array[count] = (int) (((ShortBuffer) buffer).get());
          ++count;
        }
      }
    }
    return array;
  }
}

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

src = VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
} else {
  if (buffer.hasArray()) {
    array = buffer.array();
    offset = buffer.arrayOffset();

代码示例来源: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: jMonkeyEngine/jmonkeyengine

Buffer bwBuff = mesh.getBuffer(Type.BoneWeight).getData();
Buffer biBuff = mesh.getBuffer(Type.BoneIndex).getData();
if (!biBuff.hasArray() || !bwBuff.hasArray()) {
  mesh.prepareForAnim(true); // prepare for software animation

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

Buffer bwBuff = mesh.getBuffer(Type.BoneWeight).getData();
Buffer biBuff = mesh.getBuffer(Type.BoneIndex).getData();
if (!biBuff.hasArray() || !bwBuff.hasArray()) {
  mesh.prepareForAnim(true); // prepare for software animation

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

if (!indices.getData().hasArray()) {
  if (indices.getFormat() == Format.UnsignedByte) {
    ByteBuffer originalIndex = (ByteBuffer) indices.getData();
if (!weights.getData().hasArray()) {
  FloatBuffer originalWeight = (FloatBuffer) weights.getData();
  FloatBuffer arrayWeight = FloatBuffer.allocate(originalWeight.capacity());

代码示例来源:origin: ch.unibas.cs.gravis/scalismo-native-stub

@Override
public final boolean hasArray() {
  return buffer.hasArray();
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

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

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

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

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

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

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

代码示例来源:origin: org.roaringbitmap/RoaringBitmap

/**
 * Checks whether the Buffer is backed by a simple array. In java, a Buffer is an abstraction that
 * can represent various data, from data on disk all the way to native Java arrays. Like all
 * abstractions, a Buffer might carry a performance penalty. Thus, we sometimes check whether the
 * Buffer is simply a wrapper around a Java array. In these instances, it might be best, from a
 * performance point of view, to access the underlying array (using the array()) method.
 * @param b the provided Buffer
 * @return whether the Buffer is backed by a simple array
 */
protected static boolean isBackedBySimpleArray(Buffer b) {
 return b.hasArray() && (b.arrayOffset() == 0);
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

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

/**
 * Returns the underlying Java array containing the data of the
 * given Buffer, or null if the Buffer is not backed by a Java array.
 *
 * @param b the Buffer to be queried
 * @return the Java array containing the Buffer's data, or null if
 * there is none
 */
static Object getBaseArray(Buffer b) {
  return b.hasArray() ? b.array() : null;
}

代码示例来源: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");
  }
}

相关文章