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 @Test
public void testInputOutput() throws Exception { 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>(); ArrayList<Bundle> list = new ArrayList<Bundle>();

View File

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

View File

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

View File

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