Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not use SimpleDiskCache. #1

Open
MustafaBaquari opened this issue Jun 24, 2013 · 2 comments
Open

Could not use SimpleDiskCache. #1

MustafaBaquari opened this issue Jun 24, 2013 · 2 comments

Comments

@MustafaBaquari
Copy link

I used this code to cache and retrive an Image file. The bitmap returned in last line was null. I used debug and observed each step and in every step there was something in all the variables. (I mean to say they were not null except for bitmap in last line.) I know there is a method to get bitmaps directly but I wanted a method to write any type of file in cache and retrieve them.

                    SimpleDiskCache cache = SimpleDiskCache.open(getCacheDir(), 1, (long) 1024 * 1024 *10 ); // 10 MB
                    ImageHandler ih = new ImageHandler(context);
                    URL url = new URL("ImageUrl");
                    URLConnection conection = url.openConnection();
                    conection.connect();
                    InputStream is = url.openStream();
                    cache.put("test", is);
                    InputStreamEntry returnIS = cache.getInputStream("test");
                    InputStream is2 = returnIS.getInputStream();
                    returnIS.close();
                    is.close();
                    System.out.println(is2.toString().trim());
                    Bitmap bmp = BitmapFactory.decodeStream(is2);
@fhucho
Copy link
Owner

fhucho commented Jul 26, 2013

Not sure if it would solve the problem, but I think you should call is.close(); immediately after cache.put("test", is);

@fhucho fhucho closed this as completed Jul 26, 2013
@fhucho fhucho reopened this Jul 26, 2013
@jemshit
Copy link

jemshit commented Jul 12, 2016

How to store Bitmap with String key ? @fhucho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants