@Override public Bitmap saveDataToCacheAndReturnData(Bitmap data, Object cacheKey) throws CacheSavingException { BufferedOutputStream out = null; try { File cacheFile = getCacheFile(cacheKey); out = new BufferedOutputStream(new FileOutputStream(cacheFile)); boolean didCompress = data.compress(compressFormat, quality, out); if (!didCompress) { throw new CacheSavingException(String.format("Could not compress bitmap for path: %s", getCacheFile(cacheKey).getAbsolutePath())); } return data; } catch (IOException e) { throw new CacheSavingException(e); } finally { IOUtils.closeQuietly(out); } }