public final class TypedArrayBuffer
extends java.lang.Object
Buffers and JavaScript TypedArrays.
Buffers can be direct buffers or
indirect buffers. Indirect buffers use an underlying array (like
int[] in Java or Array[Int] in Scala). Direct buffers are
supposed to use off-heap memory.
In a JavaScript environment, the equivalent of off-heap memory for buffers of primitive numeric types are TypedArrays.
This class provides methods to wrap TypedArrays as direct Buffers, and extract references to TypedArrays from direct Buffers.
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object |
arrayBuffer(java.nio.Buffer buffer)
Returns the JavaScript
ArrayBuffer backing the provided
Buffer. |
static int |
arrayBufferOffset(java.nio.Buffer buffer)
Returns the offset within the JavaScript
ArrayBuffer backing the
provided Buffer. |
static java.lang.Object |
dataView(java.nio.Buffer buffer)
Returns a JavaScript
DataView of the provided
Buffer. |
static boolean |
hasArrayBuffer(java.nio.Buffer buffer)
Tests whether the given
Buffer is backed by an accessible
JavaScript ArrayBuffer. |
static boolean |
hasTypedArray(java.nio.Buffer buffer)
Tests whether the given
Buffer is backed by an accessible
JavaScript TypedArray. |
static java.lang.Object |
typedArray(java.nio.Buffer buffer)
Returns a JavaScript
TypedArray view of the provided
Buffer. |
static java.nio.FloatBuffer |
wrapFloat32Array(java.lang.Object array)
Wraps a JavaScript
Float32Array as a direct
FloatBuffer. |
static java.nio.DoubleBuffer |
wrapFloat64Array(java.lang.Object array)
Wraps a JavaScript
Float64Array as a direct
DoubleBuffer. |
static java.nio.ShortBuffer |
wrapInt16Array(java.lang.Object array)
Wraps a JavaScript
Int16Array as a direct
ShortBuffer. |
static java.nio.IntBuffer |
wrapInt32Array(java.lang.Object array)
Wraps a JavaScript
Int32Array as a direct
IntBuffer. |
static java.nio.ByteBuffer |
wrapInt8Array(java.lang.Object array)
Wraps a JavaScript
Int8Array as a direct
ByteBuffer. |
static java.nio.CharBuffer |
wrapUint16Array(java.lang.Object array)
Wraps a JavaScript
Uint16Array as a direct
CharBuffer. |
public static final java.nio.ByteBuffer wrapInt8Array(java.lang.Object array)
Int8Array as a direct
ByteBuffer.
The provided array parameter must be a valid JavaScript
Int8Array, otherwise the behavior of this method is not
specified.
The returned ByteBuffer has the following properties:
capacity() equal to the array.length.position() is 0 and its limit() is its capacity.Int8Array:
changes to one are reflected on the other.array - a JavaScript Int8Arraypublic static final java.nio.CharBuffer wrapUint16Array(java.lang.Object array)
Uint16Array as a direct
CharBuffer.
The provided array parameter must be a valid JavaScript
Uint16Array, otherwise the behavior of this method is not
specified.
The returned CharBuffer has the following properties:
capacity() equal to the array.length.position() is 0 and its limit() is its capacity.Uint16Array:
changes to one are reflected on the other.array - a JavaScript Uint16Arraypublic static final java.nio.ShortBuffer wrapInt16Array(java.lang.Object array)
Int16Array as a direct
ShortBuffer.
The provided array parameter must be a valid JavaScript
Int16Array, otherwise the behavior of this method is not
specified.
The returned ShortBuffer has the following properties:
capacity() equal to the array.length.position() is 0 and its limit() is its capacity.Int16Array:
changes to one are reflected on the other.array - a JavaScript Int16Arraypublic static final java.nio.IntBuffer wrapInt32Array(java.lang.Object array)
Int32Array as a direct
IntBuffer.
The provided array parameter must be a valid JavaScript
Int32Array, otherwise the behavior of this method is not
specified.
The returned IntBuffer has the following properties:
capacity() equal to the array.length.position() is 0 and its limit() is its capacity.Int32Array:
changes to one are reflected on the other.array - a JavaScript Int32Arraypublic static final java.nio.FloatBuffer wrapFloat32Array(java.lang.Object array)
Float32Array as a direct
FloatBuffer.
The provided array parameter must be a valid JavaScript
Float32Array, otherwise the behavior of this method is not
specified.
The returned FloatBuffer has the following properties:
capacity() equal to the array.length.position() is 0 and its limit() is its capacity.Float32Array:
changes to one are reflected on the other.array - a JavaScript Float32Arraypublic static final java.nio.DoubleBuffer wrapFloat64Array(java.lang.Object array)
Float64Array as a direct
DoubleBuffer.
The provided array parameter must be a valid JavaScript
Float64Array, otherwise the behavior of this method is not
specified.
The returned DoubleBuffer has the following properties:
capacity() equal to the array.length.position() is 0 and its limit() is its capacity.Float64Array:
changes to one are reflected on the other.array - a JavaScript Float64Arraypublic static final boolean hasArrayBuffer(java.nio.Buffer buffer)
Buffer is backed by an accessible
JavaScript ArrayBuffer.
This is true for all read-write direct buffers, in particular for those
created with any of the wrapX methods of this class.
If this method returns true, then arrayBuffer(buffer),
arrayBufferOffset(buffer) and dataView(buffer) do not
throw any UnsupportedOperationException.
buffer is backed by an
accessible JavaScript ArrayBufferarrayBuffer(Buffer),
arrayBufferOffset(Buffer),
dataView(Buffer)public static final java.lang.Object arrayBuffer(java.nio.Buffer buffer)
throws java.lang.UnsupportedOperationException
ArrayBuffer backing the provided
Buffer.
The buffer may represent a view of the returned
ArrayBuffer that does not start at index 0. Use the method
arrayBufferOffset(Buffer) to retrieve the offset
within the ArrayBuffer.
ArrayBuffer backing the provided bufferjava.lang.UnsupportedOperationException - if the provided buffer is read-only or is not backed by a
JavaScript ArrayBuffer, i.e., if hasArrayBuffer(buffer)
returns falsehasArrayBuffer(Buffer),
arrayBufferOffset(Buffer)public static final int arrayBufferOffset(java.nio.Buffer buffer)
throws java.lang.UnsupportedOperationException
ArrayBuffer backing the
provided Buffer.ArrayBuffer backing the
provided buffer where the latter startsjava.lang.UnsupportedOperationException - if the provided buffer is read-only or is not backed by a
JavaScript ArrayBuffer, i.e., if hasArrayBuffer(buffer)
returns falsehasArrayBuffer(Buffer),
arrayBuffer(Buffer)public static final java.lang.Object dataView(java.nio.Buffer buffer)
throws java.lang.UnsupportedOperationException
DataView of the provided
Buffer.DataView of the provided bufferjava.lang.UnsupportedOperationException - if the provided buffer is read-only or is not backed by a
JavaScript ArrayBuffer, i.e., if hasArrayBuffer(buffer)
returns falsehasArrayBuffer(Buffer)public static final boolean hasTypedArray(java.nio.Buffer buffer)
Buffer is backed by an accessible
JavaScript TypedArray.
This is true when all of the following conditions apply:
TypedArrays, andLongBuffer.In particular, it is true for all Buffers created with
any of the wrapXArray methods of this class.
If this method returns true, then typedArray(buffer)
does not throw any UnsupportedOperationException.
buffer is backed by an
accessible JavaScript TypedArraytypedArray(Buffer)public static final java.lang.Object typedArray(java.nio.Buffer buffer)
throws java.lang.UnsupportedOperationException
TypedArray view of the provided
Buffer.
The particular type of TypedArray depends on the type of buffer:
Int8Array for a ByteBufferUint16Array for a CharBufferInt16Array for a ShortBufferInt32Array for a IntBufferFloat32Array for a FloatBufferFloat64Array for a DoubleBufferTypedArray view of the provided bufferjava.lang.UnsupportedOperationException - if the provided buffer is read-only or is not backed by a
JavaScript TypedArray, i.e., if hasTypedArray(buffer)
returns falsehasTypedArray(Buffer)