@Override public InputStream saveDataToCacheAndReturnData(InputStream data, Object cacheKey) throws CacheSavingException { FileOutputStream output = null; // special case for big inputstream object : as it can be read // only once and is too big to be locally // duplicated, // 1) we save it in file // 2) we load and return it from the file try { output = new FileOutputStream(getCacheFile(cacheKey)); IOUtils.copy(data, output); return new FileInputStream(getCacheFile(cacheKey)); } catch (IOException e) { throw new CacheSavingException(e); } finally { IOUtils.closeQuietly(output); } }