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

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

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

Buffer.arrayOffset介绍

[英]Returns the offset into the array returned by array of the first element of the buffer (optional operation). The backing array (if there is one) is not necessarily the same size as the buffer, and position 0 in the buffer is not necessarily the 0th element in the array. Use buffer.array()[offset + buffer.arrayOffset() to access element offsetin buffer.

Use hasArray to ensure this method won't throw. (A separate call to isReadOnly is not necessary.)
[中]将偏移量返回到缓冲区第一个元素的数组返回的数组中(可选操作)。后备数组(如果有)不一定与缓冲区大小相同,缓冲区中的位置0不一定是数组中的第0个元素。使用缓冲区。array()[offset+buffer.arrayOffset()访问缓冲区中的元素offsetin。
使用hasArray确保此方法不会抛出。(不需要单独致电isReadOnly。)

代码示例

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

if (buffer.hasArray()) {
  array = buffer.array();
  offset = buffer.arrayOffset();
} else {
  int pos = buffer.position();

代码示例来源: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: com.facebook.presto.cassandra/cassandra-driver

@Override
public int offset(Object o) {
  Buffer buffer = (Buffer) o;
  return buffer.arrayOffset() + buffer.position();
}

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

@Override
public int offset(Object o) {
  Buffer buffer = (Buffer) o;
  return buffer.arrayOffset() + buffer.position();
}

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

@Override
public int offset(Object o) {
  Buffer buffer = (Buffer) o;
  return buffer.arrayOffset() + buffer.position();
}

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

@Override
public int offset(Object o) {
  Buffer buffer = (Buffer) o;
  return buffer.arrayOffset() + buffer.position();
}

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

@Override
public int offset(Object o) {
  Buffer buffer = (Buffer) o;
  return buffer.arrayOffset() + buffer.position();
}

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

@Override
public int offset(Object o) {
  Buffer buffer = (Buffer) o;
  return buffer.arrayOffset() + buffer.position();
}

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

/**
   * 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: ch.unibas.cs.gravis/scalismo-native-stub

@Override
public final int arrayOffset() {
  if( hasArray() ) {
    return buffer.arrayOffset();
  } else {
    return 0;
  }
}

代码示例来源: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: MobiVM/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: FlexoVM/flexovm

/**
   * 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: ibinti/bugvm

/**
   * 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: 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: 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: 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.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);
  }
}

相关文章