即使请求相同,Java InputSream的hascode也会每次都不同 [英] Java InputSream hascode is different each time even when the request is same

查看:72
本文介绍了即使请求相同,Java InputSream的hascode也会每次都不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询不特定于 UniversalImageLoader ,但是因为我正在尝试使用内容流加载我面临的以下问题的图像.

我正在使用输入流"stream://"来使用ImageLoader.一切正常,除了针对同一请求的输入流的哈希码生成方式不同之外,因此迫使图像加载器再次从网络而不是从磁盘下载图像.

我该怎么做才能解决它.

PS:我尝试遵循

哈希码的基本问题与上面的示例相同,在该示例中,即使inputStream对象是第二个日志哈希码也不同于第一个日志哈希码使用的是相同的.

 //String imageId = "stream://" + inputStream.hashCode();
            //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode:  " + imageId);
            //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode();
            //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode:  " + imageId2);

尽管不能完全回答上述问题,但是我能够通过不将哈希码作为id传递给通用图像加载器来解决此问题.相反,我通过了唯一的文件ID,现在可以很好地显示来自内存缓存的图像.

I have a query not particular to UniversalImageLoader but because i am trying to use the content stream to load the image i am facing following issue.

I am using input stream "stream://" to be able to use ImageLoader. Everything is working fine except that the hashcode of the input stream for the same request is generated differently and hence forces the imageloader to download the image again from the network instead of the disk.

What should i do to fix it.

PS: I tried to follow the answer from here

The code to get InputStream is (The UtilityMethod is noting just an async task):

 public void displayContentImage(final String fileId, final ImageView imageView) {
    UtilityMethods.startMyTask(new AsyncTask<Object, Void, InputStream>() {

        @Override
        protected InputStream doInBackground(Object... params) {
            CMServiceGateway cmServiceGateway = new CMServiceGateway();
            final InputStream inputStream = cmServiceGateway.GetContentAsStream(fileId);
            if (inputStream != null) {
                //String imageId = "stream://" + inputStream.hashCode();
                //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode:  " + imageId);
                //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode();
                //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode:  " + imageId2);
                return inputStream;
            }
            return null;
        }

        @Override
        protected void onPostExecute(InputStream inputStream) {
            if (inputStream != null) {
                displayImage(inputStream, imageView);
            }
        }
    });
}

解决方案

The basic problem of hash code equal like the sample above where you will find that the second log hash code is different than first log hash code even if the inputStream object used is same.

 //String imageId = "stream://" + inputStream.hashCode();
            //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode:  " + imageId);
            //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode();
            //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode:  " + imageId2);

Although not answering the above question exactly but I am able to resolve this problem by not passing the hashcode to the universal image loader as id. Instead i passed the unique file Id's and it worked well now to display image from memory cache.

这篇关于即使请求相同,Java InputSream的hascode也会每次都不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆