title: Implementing Image Lru Caching with DiskLruCache
body: <p>I am trying to implement Disk based image lru cache with jake wharton DiskLruCache library. <a href="https://github.com/JakeWharton/DiskLruCache" rel="nofollow">link to library</a>. I am using a code snippet from <a href="http://shaikhhamadali.blogspot.com/2013/09/memory-leak-and-out-of-memory-error_3.html" rel="nofollow">here</a>.</p>
  
  <p>Methods i am having trouble with are this </p>
  
  <pre><code>private boolean writeBitmapToFile(Bitmap bitmap, DiskLruCache.Editor editor)
          throws IOException, FileNotFoundException {
      OutputStream out = null;
      try {
          out = new BufferedOutputStream(editor.newOutputStream(0), Utils.IO_BUFFER_SIZE);
          return bitmap.compress(mCompressFormat, mCompressQuality, out);
      } finally {
          if (out != null) {
              out.close();
          }
      }
  }
  </code></pre>
  
  <p>where editor.newOutputStream(0) does not exist, and this one </p>
  
  <pre><code>public Bitmap getBitmap(String key) {
  
      Bitmap bitmap = null;
      DiskLruCache.Snapshot snapshot = null;
      try {
  
          snapshot = mDiskCache.get(key);
          if (snapshot == null) {
              return null;
          }
          final InputStream in = snapshot.getInputStream(0);
          if (in != null) {
              final BufferedInputStream buffIn =
                      new BufferedInputStream(in, Utils.IO_BUFFER_SIZE);
              bitmap = BitmapFactory.decodeStream(buffIn);
          }
      } catch (IOException e) {
          e.printStackTrace();
      } finally {
          if (snapshot != null) {
              snapshot.close();
          }
      }
  
          Log.d("cache_test_DISK_", bitmap == null ? "" : "image read from disk " + key);
  
      return bitmap;
  
  }
  </code></pre>
  
  <p>where snapshot.getInputStream(0) also does not exist. </p>
  
  <p>What am i doing wrong? I have placed the jar with the library and all is well, are these methods deleted from DiskLruCache library? Is there other way to do this now? I can't find any examples or tutorials.</p>
  
  <p>Library version is the latest disklrucache-2.0.2</p>