示例#1
0
        public Response <Bitmap> Load(Uri uri, bool localCacheOnly)
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich)
            {
                InstallCacheIfNeeded(m_Context);
            }

            URLConnection connection = OpenConnection(uri);

            connection.UseCaches = true;
            if (localCacheOnly)
            {
                connection.SetRequestProperty("Cache-Control", "only-if-cached,max-age=" + int.MaxValue);
            }

            var httpConnection = connection as HttpURLConnection;

            if (httpConnection != null)
            {
                int responseCode = (int)httpConnection.ResponseCode;
                if (responseCode >= 300)
                {
                    httpConnection.Disconnect();
                    throw new ResponseException(responseCode + " " + httpConnection.ResponseMessage);
                }
            }

            long contentLength = connection.GetHeaderFieldInt("Content-Length", -1);
            bool fromCache     = ParseResponseSourceHeader(connection.GetHeaderField(ResponseSource));

            return(new Response <Bitmap>(connection.InputStream, fromCache, contentLength));
        }