Class TypedArrays


  • public class TypedArrays
    extends java.lang.Object
    Factory class for various typed arrays. Behavior of all other methods is undefined if isSupported() returns false.

    In client code, the various types are implemented by JavaScriptObjects, so you cannot reliable use instanceof checks on any of the returned implementations.

    • Constructor Detail

      • TypedArrays

        public TypedArrays()
    • Method Detail

      • createArrayBuffer

        public static ArrayBuffer createArrayBuffer​(int length)
        Create a new ArrayBuffer of length bytes.
        Parameters:
        length - length of buffer in bytes
        Returns:
        an ArrayBuffer instance
      • createDataView

        public static DataView createDataView​(ArrayBuffer buffer,
                                              int byteOffset,
                                              int byteLength)
        Create a new DataView instance on an ArrayBuffer, starting at an offset of byteOffset and continuing for length bytes.
        Parameters:
        buffer - ArrayBuffer
        byteOffset - offset into buffer
        byteLength - length of view in bytes
        Returns:
        DataView instance
      • createFloat32Array

        public static Float32Array createFloat32Array​(ArrayBuffer buffer)
        Create a Float32Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Float32Array instance
      • createFloat32Array

        public static Float32Array createFloat32Array​(ArrayBuffer buffer,
                                                      int byteOffset)
        Create a Float32Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Float32Array instance
      • createFloat32Array

        public static Float32Array createFloat32Array​(ArrayBuffer buffer,
                                                      int byteOffset,
                                                      int length)
        Create a Float32Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Float32Array instance
      • createFloat64Array

        public static Float64Array createFloat64Array​(ArrayBuffer buffer)
        Create a Float64Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).

        Note that Safari does not currently support Float64 Arrays!

        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Float64Array instance
      • createFloat64Array

        public static Float64Array createFloat64Array​(ArrayBuffer buffer,
                                                      int byteOffset)
        Create a Float64Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).

        Note that Safari does not currently support Float64 Arrays!

        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Float64Array instance
      • createFloat64Array

        public static Float64Array createFloat64Array​(ArrayBuffer buffer,
                                                      int byteOffset,
                                                      int length)
        Create a Float64Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.

        Note that Safari does not currently support Float64 Arrays!

        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Float64Array instance
      • createFloat64Array

        public static Float64Array createFloat64Array​(int length)
        Create a Float64Array instance of length elements, backed by a new ArrayBuffer.

        Note that Safari does not currently support Float64 Arrays!

        Parameters:
        length - size of array
        Returns:
        a Float64Array instance
      • createInt16Array

        public static Int16Array createInt16Array​(ArrayBuffer buffer)
        Create a Int16Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Int16Array instance
      • createInt16Array

        public static Int16Array createInt16Array​(ArrayBuffer buffer,
                                                  int byteOffset)
        Create a Int16Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Int16Array instance
      • createInt16Array

        public static Int16Array createInt16Array​(ArrayBuffer buffer,
                                                  int byteOffset,
                                                  int length)
        Create a Int16Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Int16Array instance
      • createInt16Array

        public static Int16Array createInt16Array​(int length)
        Create a Int16Array instance of length elements, backed by a new ArrayBuffer.
        Parameters:
        length - size of array
        Returns:
        a Int16Array instance
      • createInt32Array

        public static Int32Array createInt32Array​(ArrayBuffer buffer)
        Create a Int32Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Int32Array instance
      • createInt32Array

        public static Int32Array createInt32Array​(ArrayBuffer buffer,
                                                  int byteOffset)
        Create a Int32Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Int32Array instance
      • createInt32Array

        public static Int32Array createInt32Array​(ArrayBuffer buffer,
                                                  int byteOffset,
                                                  int length)
        Create a Int32Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Int32Array instance
      • createInt32Array

        public static Int32Array createInt32Array​(int length)
        Create a Int32Array instance of length elements, backed by a new ArrayBuffer.
        Parameters:
        length - size of array
        Returns:
        a Int32Array instance
      • createInt8Array

        public static Int8Array createInt8Array​(ArrayBuffer buffer)
        Create a Int8Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end.
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Int8Array instance
      • createInt8Array

        public static Int8Array createInt8Array​(ArrayBuffer buffer,
                                                int byteOffset)
        Create a Int8Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Int8Array instance
      • createInt8Array

        public static Int8Array createInt8Array​(ArrayBuffer buffer,
                                                int byteOffset,
                                                int length)
        Create a Int8Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Int8Array instance
      • createInt8Array

        public static Int8Array createInt8Array​(int length)
        Create a Int8Array instance of length elements, backed by a new ArrayBuffer.
        Parameters:
        length - size of array
        Returns:
        a Int8Array instance
      • createUint16Array

        public static Uint16Array createUint16Array​(ArrayBuffer buffer)
        Create a Uint16Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Uint16Array instance
      • createUint16Array

        public static Uint16Array createUint16Array​(ArrayBuffer buffer,
                                                    int byteOffset)
        Create a Uint16Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Uint16Array instance
      • createUint16Array

        public static Uint16Array createUint16Array​(ArrayBuffer buffer,
                                                    int byteOffset,
                                                    int length)
        Create a Uint16Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Uint16Array instance
      • createUint16Array

        public static Uint16Array createUint16Array​(int length)
        Create a Uint16Array instance of length elements, backed by a new ArrayBuffer.
        Parameters:
        length - size of array
        Returns:
        a Uint16Array instance
      • createUint32Array

        public static Uint32Array createUint32Array​(ArrayBuffer buffer)
        Create a Uint32Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Uint32Array instance
      • createUint32Array

        public static Uint32Array createUint32Array​(ArrayBuffer buffer,
                                                    int byteOffset)
        Create a Uint32Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Uint32Array instance
      • createUint32Array

        public static Uint32Array createUint32Array​(ArrayBuffer buffer,
                                                    int byteOffset,
                                                    int length)
        Create a Uint32Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Uint32Array instance
      • createUint32Array

        public static Uint32Array createUint32Array​(int length)
        Create a Uint32Array instance of length elements, backed by a new ArrayBuffer.
        Parameters:
        length - size of array
        Returns:
        a Uint32Array instance
      • createUint8Array

        public static Uint8Array createUint8Array​(ArrayBuffer buffer)
        Create a Uint8Array instance on buffer, starting at starting at the beginning of the buffer and continuing to the end (which must be an integral number of elements).
        Parameters:
        buffer - underlying ArrayBuffer
        Returns:
        an Uint8Array instance
      • createUint8Array

        public static Uint8Array createUint8Array​(ArrayBuffer buffer,
                                                  int byteOffset)
        Create a Uint8Array instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Uint8Array instance
      • createUint8Array

        public static Uint8Array createUint8Array​(ArrayBuffer buffer,
                                                  int byteOffset,
                                                  int length)
        Create a Uint8Array instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Uint8Array instance
      • createUint8Array

        public static Uint8Array createUint8Array​(int length)
        Create a Uint8Array instance of length elements, backed by a new ArrayBuffer.
        Parameters:
        length - size of array
        Returns:
        a Uint8Array instance
      • createUint8ClampedArray

        public static Uint8ClampedArray createUint8ClampedArray​(ArrayBuffer buffer,
                                                                int byteOffset)
        Create a Uint8ClampedArray instance on buffer, starting at byteOffset into the buffer, continuing to the end of the buffer.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        Returns:
        an Uint8ClampedArray instance
      • createUint8ClampedArray

        public static Uint8ClampedArray createUint8ClampedArray​(ArrayBuffer buffer,
                                                                int byteOffset,
                                                                int length)
        Create a Uint8ClampedArray instance on buffer, starting at byteOffset into the buffer, continuing for length elements.
        Parameters:
        buffer - underlying ArrayBuffer
        byteOffset - byte offset from the start of buffer
        length - number of elements in the resulting array
        Returns:
        an Uint8ClampedArray instance
      • isSupported

        public static boolean isSupported()
        Check if the current environment supports typed arrays. Behavior of the various createXXX methods is undefined if this method returns false, but will typically throw some exception.
        Returns:
        true if typed arrays are support.