always use getContentResolver().open(Input/Output)Stream, opening streams diffrently from URIs seems to be redundent

https://developer.android.com/reference/android/content/ContentResolver#openInputStream(android.net.Uri)

spotBug is also happier with those streams not getting closed within the scope of that function, for some reason unknown
This commit is contained in:
Katharine Chui
2021-11-23 18:30:51 +08:00
parent 63fad8bae1
commit 3ba42aad6d

View File

@@ -92,12 +92,7 @@ public class ImportExportActivity extends CatimaAppCompatActivity {
return;
}
try {
OutputStream writer;
if (uri.getScheme() != null) {
writer = getContentResolver().openOutputStream(uri);
} else {
writer = new FileOutputStream(result.toString());
}
OutputStream writer = getContentResolver().openOutputStream(uri);
Log.e(TAG, "Starting file export with: " + result.toString());
startExport(writer, uri, exportPassword.toCharArray(), true);
} catch (IOException e) {
@@ -174,28 +169,12 @@ public class ImportExportActivity extends CatimaAppCompatActivity {
}
private void openFileForImport(Uri uri, char[] password) {
InputStream reader = null;
try {
if (uri.getScheme() != null) {
reader = getContentResolver().openInputStream(uri);
} else {
reader = new FileInputStream(uri.toString());
}
InputStream reader = getContentResolver().openInputStream(uri);
Log.e(TAG, "Starting file import with: " + uri.toString());
startImport(reader, uri, importDataFormat, password, true);
} catch (IOException e) {
Log.e(TAG, "Failed to import file: " + uri.toString(), e);
if (reader != null) {
try {
reader.close();
} catch (IOException ee) {
Log.e(TAG, "failed closing reader after opening exception");
ee.printStackTrace();
throw new RuntimeException("SpotBug :<");
}
}
onImportComplete(ImportExportResult.GenericFailure, uri, importDataFormat);
}
}