Example #1
0
        protected override Object LoadResource(Uri uri, ContentResolver contentResolver)
        {
            var handle = InputStreamAdapter.ToLocalJniHandle(LoadResource_T(uri, contentResolver));

            try
            {
                return(new Object(handle, JniHandleOwnership.TransferLocalRef));
            }
            finally
            {
                JNIEnv.DeleteLocalRef(handle);
            }
        }
Example #2
0
        protected override Object LoadResource(AssetManager assetManager, string path)
        {
            var handle = InputStreamAdapter.ToLocalJniHandle(LoadResource_T(assetManager, path));

            try
            {
                return(new Object(handle, JniHandleOwnership.TransferLocalRef));
            }
            finally
            {
                JNIEnv.DeleteLocalRef(handle);
            }
        }
        public Session CreateSession()
        {
            if (Rulebase == null)
            {
                using (var stream = _rulebaseStreamProvider.GetStream())
                {
                    using (var rulebaseStream = new InputStreamAdapter(stream))
                    {
                        Rulebase = Engine.INSTANCE.GetRulebase(rulebaseStream);
                    }
                }
            }

            return(Engine.INSTANCE.CreateSession(Rulebase));
        }
        public Session CreateOPASession(Stream rulebaseStream, IDataEntity globalEntity)
        {
            if (!RulebaseInitialised)
            {
                InputStream stream = new InputStreamAdapter(rulebaseStream);
                Rulebase            = Engine.INSTANCE.GetRulebase(stream);
                RulebaseInitialised = true;
            }

            Session session = Engine.INSTANCE.CreateSession(Rulebase);

            var inputGlobalInstance = session.GetGlobalEntityInstance();

            MapGlobalDataEntityToOpa(globalEntity, session, inputGlobalInstance);

            return(session);
        }
Example #5
0
        void TestInputStream(TextView textview)
        {
            InputStreamAdapter jis = new InputStreamAdapter(new System.IO.MemoryStream(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }));

            byte[] buffer  = new byte[10];
            int    cnt     = jis.Read(buffer);
            bool   success = cnt == 8;

            for (int i = 0; i < cnt; i++)
            {
                if (buffer[i] != (byte)i)
                {
                    success = false;
                }
            }
            textview.Text += "\n\nTestInputStream round trip success: " + success;
        }
Example #6
0
        public async Task <IImageSourceServiceResult <Drawable>?> GetDrawableAsync(IStreamImageSource imageSource, Context context, CancellationToken cancellationToken = default)
        {
            if (imageSource.IsEmpty)
            {
                return(null);
            }

            try
            {
                var stream = await imageSource.GetStreamAsync(cancellationToken).ConfigureAwait(false);

                // We can use the .NET stream directly because we register the InputStreamModelLoader.
                // There are 2 alternatives:
                //  - Load the bitmap manually and pass that along, but then we do not get the decoding features.
                //  - Copy the stream into a byte array and that is double memory usage - especially for large streams.
                var inputStream = new InputStreamAdapter(stream);

                var result = await Glide
                             .With(context)
                             .Load(inputStream)
                             .SetDiskCacheStrategy(DiskCacheStrategy.None)
                             .SubmitAsync(context, cancellationToken)
                             .ConfigureAwait(false);

                if (result == null)
                {
                    throw new InvalidOperationException("Unable to load image stream.");
                }

                return(result);
            }
            catch (Exception ex)
            {
                Logger?.LogWarning(ex, "Unable to load image stream.");
                throw;
            }
        }