本文整理了Java中java.nio.Buffer.array()
方法的一些代码示例,展示了Buffer.array()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.array()
方法的具体详情如下:
包路径:java.nio.Buffer
类名称:Buffer
方法名:array
[英]Returns the array that backs this buffer (optional operation). The returned value is the actual array, not a copy, so modifications to the array write through to the buffer.
Subclasses should override this method with a covariant return type to provide the exact type of the array.
Use hasArray to ensure this method won't throw. (A separate call to isReadOnly is not necessary.)
[中]返回支持此缓冲区的数组(可选操作)。返回的值是实际数组,而不是副本,因此对数组的修改将写入缓冲区。
子类应使用协变返回类型重写此方法,以提供数组的确切类型。
使用hasArray确保此方法不会抛出。(不需要单独致电isReadOnly。)
代码示例来源: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: robovm/robovm
} else {
if (buffer.hasArray()) {
array = buffer.array();
offset = buffer.arrayOffset();
} 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: 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: 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: 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: 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: io.prestosql.cassandra/cassandra-driver
@Override
public Object object(Object o) {
return ((Buffer) o).array();
}
代码示例来源: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);
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
@Override
public Object object(Object o) {
return ((Buffer) o).array();
}
代码示例来源: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: ch.unibas.cs.gravis/scalismo-native-stub
@Override
public Object array() throws UnsupportedOperationException {
return buffer.array();
}
代码示例来源: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: 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: 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: 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: 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: gov.nasa.gsfc.heasarc/nom-tam-fits
protected void prepareUncompressedData(Object data, Header header) throws FitsException {
tiledImageOperation().readPrimaryHeaders(header);
Buffer source = tiledImageOperation().getBaseType().newBuffer(this.tiledImageOperation.getBufferSize());
ArrayFuncs.copyInto(data, source.array());
tiledImageOperation().prepareUncompressedData(source);
}
代码示例来源:origin: nom-tam-fits/nom-tam-fits
protected void prepareUncompressedData(Object data, Header header) throws FitsException {
tiledImageOperation().readPrimaryHeaders(header);
Buffer source = tiledImageOperation().getBaseType().newBuffer(this.tiledImageOperation.getBufferSize());
ArrayFuncs.copyInto(data, source.array());
tiledImageOperation().prepareUncompressedData(source);
}
内容来源于网络,如有侵权,请联系作者删除!