consolidate: split into two steps, can pick up at second step if anything fails

This commit is contained in:
Vincent Breitmoser
2014-08-19 15:45:42 +02:00
parent 8d668d170c
commit c725239a69
7 changed files with 112 additions and 26 deletions

View File

@@ -92,6 +92,10 @@ public class FileImportCache<E extends Parcelable> {
}
public Iterator<E> readCache() throws IOException {
return readCache(true);
}
public Iterator<E> readCache(final boolean deleteAfterRead) throws IOException {
File cacheDir = mContext.getCacheDir();
if (cacheDir == null) {
@@ -166,7 +170,10 @@ public class FileImportCache<E extends Parcelable> {
if (!closed) {
try {
ois.close();
tempFile.delete();
if (deleteAfterRead) {
//noinspection ResultOfMethodCallIgnored
tempFile.delete();
}
} catch (IOException e) {
// nvm
}
@@ -177,4 +184,17 @@ public class FileImportCache<E extends Parcelable> {
};
}
public boolean delete() throws IOException {
File cacheDir = mContext.getCacheDir();
if (cacheDir == null) {
// https://groups.google.com/forum/#!topic/android-developers/-694j87eXVU
throw new IOException("cache dir is null!");
}
final File tempFile = new File(cacheDir, mFilename);
return tempFile.delete();
}
}