@Override protected <T> T doLoad(Type type, String key) { if (mDiskLruCache == null) { return null; } try { DiskLruCache.Editor edit = mDiskLruCache.edit(key); if (edit == null) { return null; } InputStream source = edit.newInputStream(0); T value; if (source != null) { value = mDiskConverter.load(source,type); Utils.close(source); edit.commit(); return value; } edit.abort(); } catch (IOException e) { e.printStackTrace(); } return null; }
/** * Returns the last committed value as a string, or null if no value * has been committed. */ public String getString(int index) throws IOException { InputStream in = newInputStream(index); return in != null ? inputStreamToString(in) : null; }