asUint8List method

Uint8List asUint8List({
  1. bool releaseOriginal = false,
})

Returns this byte buffer as a Uint8List.

If releaseOriginal is true, this byte buffer will be released.

Throws StateError if the buffer is not direct (see JByteBuffer.allocateDirect) or the JVM does not support the direct buffer operations or the object is an unaligned view buffer and the processor does not support unaligned access.

Implementation

Uint8List asUint8List({bool releaseOriginal = false}) {
  _ensureIsDirect();
  final address = _directBufferAddress();
  final capacity = _directBufferCapacity();
  final token = releaseOriginal
      ? reference.pointer
      : Jni.env.NewGlobalRef(reference.pointer);
  if (releaseOriginal) {
    reference.setAsReleased();
  }
  return address.cast<Uint8>().asTypedList(
        capacity,
        token: token,
        finalizer: Jni.env.ptr.ref.DeleteGlobalRef.cast(),
      );
}