Esempio n. 1
0
        private static byte[] ReadBytesFromUri(Android.Net.Uri uri, Context context)
        {
            var stream          = context.ContentResolver.OpenInputStream(uri);
            var byteArrayStream = new Java.IO.ByteArrayOutputStream();

            byte[] buffer = new byte[1024];

            int i = Java.Lang.Integer.MaxValue;

            while ((i = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                byteArrayStream.Write(buffer, 0, i);
            }

            var bytes = byteArrayStream.ToByteArray();

            if (bytes.Length > (int)Common.CoreConstants.ImageSizeLimit)
            {
                return(null);
            }

            return(bytes);
        }
 public stream(Java.IO.ByteArrayOutputStream stream)
 {
     outputStream = stream;
 }
 public static System.IO.Stream toStream(this Java.IO.ByteArrayOutputStream stream)
 {
     return(new stream(stream));
 }
 public static byte[] toByteArray(this Java.IO.ByteArrayOutputStream stream)
 {
     return(stream.ToByteArray());
 }
Esempio n. 5
0
        /// <summary>
        /// 解压缩字符串(ICSharpCode.SharpZipLib版)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string _Decompress(string input)
        {
            string result = string.Empty;
            byte[] buffer = Convert.FromBase64String(input);

            Java.IO.ByteArrayOutputStream _out = new Java.IO.ByteArrayOutputStream();
            System.IO.Stream inputStream = new MemoryStream(buffer);
            GZIPInputStream gzip = new GZIPInputStream(inputStream);
            byte[] buff = new byte[256];
            int n = 0;
            while ((n = gzip.Read(buffer)) >= 0)
            {
                _out.Write(buffer, 0, n);
            }

            return _out.ToString();
        }