public FastJavaByteArray(int length, bool readOnly = true) { if (length <= 0) { throw new ArgumentOutOfRangeException(); } IsReadOnly = readOnly; IntPtr arrayHandle = JniEnvEx.NewByteArray(length); if (arrayHandle == IntPtr.Zero) { throw new OutOfMemoryException(); } SetHandle(arrayHandle, JniHandleOwnership.DoNotTransfer); Count = length; bool isCopy = false; unsafe { Raw = JniEnvEx.GetByteArrayElements(arrayHandle, ref isCopy); } }
protected override void Dispose(bool disposing) { unsafe { // tell Java that we're done with this array JniEnvEx.ReleaseByteArrayElements(Handle, Raw, IsReadOnly ? PrimitiveArrayReleaseMode.Release : PrimitiveArrayReleaseMode.CommitAndRelease); } base.Dispose(disposing); }
public FastJavaByteArray(IntPtr handle, bool readOnly = true) : base(handle, JniHandleOwnership.DoNotTransfer) { if (handle == IntPtr.Zero) { throw new ArgumentNullException("handle"); } IsReadOnly = readOnly; Count = JNIEnv.GetArrayLength(handle); bool isCopy = false; unsafe { Raw = JniEnvEx.GetByteArrayElements(handle, ref isCopy); } }