parametrize FileImportCache for filename

This commit is contained in:
Vincent Breitmoser 2014-08-17 00:49:14 +02:00
parent c00343d516
commit aa625d4fbf
4 changed files with 10 additions and 8 deletions

View File

@ -25,7 +25,7 @@ public class FileImportCacheTest {
@Test
public void testInputOutput() throws Exception {
FileImportCache<Bundle> cache = new FileImportCache<Bundle>(Robolectric.application);
FileImportCache<Bundle> cache = new FileImportCache<Bundle>(Robolectric.application, "test.pcl");
ArrayList<Bundle> list = new ArrayList<Bundle>();

View File

@ -477,7 +477,7 @@ public class KeychainIntentService extends IntentService
} else {
// get entries from cached file
FileImportCache<ParcelableKeyRing> cache =
new FileImportCache<ParcelableKeyRing>(this);
new FileImportCache<ParcelableKeyRing>(this, "key_import.pcl");
entries = cache.readCacheIntoList();
}

View File

@ -503,7 +503,8 @@ public class ImportKeysActivity extends ActionBarActivity {
// to prevent Java Binder problems on heavy imports
// read FileImportCache for more info.
try {
FileImportCache<ParcelableKeyRing> cache = new FileImportCache<ParcelableKeyRing>(this);
FileImportCache<ParcelableKeyRing> cache =
new FileImportCache<ParcelableKeyRing>(this, "key_import.pcl");
cache.writeCache(selectedEntries);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

View File

@ -46,10 +46,11 @@ public class FileImportCache<E extends Parcelable> {
private Context mContext;
private static final String FILENAME = "key_import.pcl";
private final String mFilename;
public FileImportCache(Context context) {
this.mContext = context;
public FileImportCache(Context context, String filename) {
mContext = context;
mFilename = filename;
}
public void writeCache(ArrayList<E> selectedEntries) throws IOException {
@ -64,7 +65,7 @@ public class FileImportCache<E extends Parcelable> {
throw new IOException("cache dir is null!");
}
File tempFile = new File(mContext.getCacheDir(), FILENAME);
File tempFile = new File(mContext.getCacheDir(), mFilename);
DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile));
@ -98,7 +99,7 @@ public class FileImportCache<E extends Parcelable> {
throw new IOException("cache dir is null!");
}
final File tempFile = new File(cacheDir, FILENAME);
final File tempFile = new File(cacheDir, mFilename);
final DataInputStream ois = new DataInputStream(new FileInputStream(tempFile));
return new Iterator<E>() {