@Override public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException { File cacheFile = getCacheFile(cacheKey); if (cacheFile.exists()) { return cacheFile.lastModified(); } else { throw new CacheLoadingException( "Data could not be found in cache for cacheKey=" + cacheKey); } }
@Override protected T deserializeData(String json) throws CacheLoadingException { try { return mJsonMapper.readValue(json, getHandledClass()); } catch (Exception e) { throw new CacheLoadingException(e); } }
@Override protected T deserializeData(String json) throws CacheLoadingException { try { return mJsonMapper.readValue(json, getHandledClass()); } catch (Exception e) { throw new CacheLoadingException(e); } }
@Override protected Bitmap readCacheDataFromFile(File file) throws CacheLoadingException { Bitmap data; FileInputStream is = null; try { is = new FileInputStream(file.getAbsolutePath()); data = BitmapFactory.decodeStream(is, null, decodingOptions); } catch (Throwable ex) { throw new CacheLoadingException(String.format("Found the file %s but could not decode bitmap.", file.getAbsolutePath()), ex); } finally { if (is != null) { IOUtils.closeQuietly(is); } } if (data == null) { throw new CacheLoadingException(String.format("Found the file %s but could not decode bitmap.", file.getAbsolutePath())); } return data; }
@Override public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException { CacheEntry cacheEntry = null; try { cacheEntry = databaseHelper.queryCacheKeyForIdFromDatabase(String.valueOf(cacheKey)); } catch (SQLException e) { throw new CacheLoadingException("Data could not be found in cache for cacheKey=" + cacheKey, e); } if (cacheEntry == null) { throw new CacheLoadingException("Data could not be found in cache for cacheKey=" + cacheKey); } return cacheEntry.getTimestamp(); }
@Override protected String readCacheDataFromFile(File file) throws CacheLoadingException { try { return FileUtils.readFileToString(file, CharEncoding.UTF_8); } catch (FileNotFoundException e) { // Should not occur (we test before if // file exists) // Do not throw, file is not cached Ln.w("file " + file.getAbsolutePath() + " does not exists", e); return null; } catch (Exception e) { throw new CacheLoadingException(e); } }
@Override protected T readCacheDataFromFile(File file) throws CacheLoadingException { try { String resultJson = null; synchronized (file.getAbsolutePath().intern()) { resultJson = FileUtils.readFileToString(file, CharEncoding.UTF_8); } if (!StringUtils.isEmpty(resultJson)) { T result = deserializeData(resultJson); return result; } throw new CacheLoadingException("Unable to restore cache content : cache file is empty"); } catch (FileNotFoundException e) { // Should not occur (we test before if file exists) // Do not throw, file is not cached Ln.w("file " + file.getAbsolutePath() + " does not exists", e); return null; } catch (CacheLoadingException e) { throw e; } catch (Exception e) { throw new CacheLoadingException(e); } }
@Override protected T deserializeData(String xml) throws CacheLoadingException { try { return serializer.read(getHandledClass(), xml); } catch (Exception e) { throw new CacheLoadingException(e); } }
return null; } catch (Exception e) { throw new CacheLoadingException(e); } finally { IOUtils.closeQuietly(fileInputStream);
@Override public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException { CacheItem<T> cacheItem = lruCache.get(cacheKey); if (cacheItem != null) { return cacheItem.getCreationDate(); } else { if (decoratedPersister != null) { return decoratedPersister.getCreationDateInCache(cacheKey); } } throw new CacheLoadingException("Data could not be found in cache for cacheKey=" + cacheKey); }
@Override protected T readCacheDataFromFile(File file) throws CacheLoadingException { try { JsonParser jsonParser = jsonFactory.createJsonParser(new FileReader(file)); T result = jsonParser.parse(getHandledClass(), null); jsonParser.close(); return result; } catch (FileNotFoundException e) { // Should not occur (we test before if file exists) // Do not throw, file is not cached Ln.w("file " + file.getAbsolutePath() + " does not exists", e); return null; } catch (Exception e) { throw new CacheLoadingException(e); } }