mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-25 23:21:50 -05:00
Make importer usable by other things handling InputStreams, like a
facility to use the Android-wide Backup Service.
This commit is contained in:
parent
9224876768
commit
4f59a04fd5
@ -28,12 +28,26 @@ import com.fsck.k9.helper.DateFormatter;
|
|||||||
|
|
||||||
public class StorageImporter {
|
public class StorageImporter {
|
||||||
public static int importPreferences(Context context, String fileName, String encryptionKey) throws StorageImportExportException {
|
public static int importPreferences(Context context, String fileName, String encryptionKey) throws StorageImportExportException {
|
||||||
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
InputStream is = new FileInputStream(fileName);
|
is = new FileInputStream(fileName);
|
||||||
return importPreferences(context, is, encryptionKey);
|
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
throw new StorageImportExportException("Failure reading settings file " + fileName, fnfe);
|
throw new StorageImportExportException("Failure opening settings file " + fileName, fnfe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int count = importPreferences(context, is, encryptionKey);
|
||||||
|
return count;
|
||||||
|
} finally {
|
||||||
|
if (is != null) {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.i(K9.LOG_TAG, "Unable to close InputStream for file " + fileName + ": " + e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static int importPreferences(Context context, InputStream is, String encryptionKey) throws StorageImportExportException {
|
public static int importPreferences(Context context, InputStream is, String encryptionKey) throws StorageImportExportException {
|
||||||
try {
|
try {
|
||||||
@ -48,13 +62,11 @@ public class StorageImporter {
|
|||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
|
|
||||||
xr.parse(new InputSource(is));
|
xr.parse(new InputSource(is));
|
||||||
is.close();
|
|
||||||
|
|
||||||
Element dataset = handler.getRootElement();
|
Element dataset = handler.getRootElement();
|
||||||
String version = dataset.attributes.get("version");
|
String version = dataset.attributes.get("version");
|
||||||
Log.i(K9.LOG_TAG, "Got settings file version " + version);
|
Log.i(K9.LOG_TAG, "Got settings file version " + version);
|
||||||
|
|
||||||
|
|
||||||
IStorageImporter storageImporter = null;
|
IStorageImporter storageImporter = null;
|
||||||
if ("1".equals(version)) {
|
if ("1".equals(version)) {
|
||||||
storageImporter = new StorageImporterVersion1();
|
storageImporter = new StorageImporterVersion1();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user