Check resolver input/output streams

This commit is contained in:
M66B
2022-03-27 13:43:45 +02:00
parent df3e0e132a
commit 1aa80a9258
16 changed files with 77 additions and 10 deletions

View File

@@ -415,8 +415,11 @@ public class FragmentContacts extends FragmentBase {
int count = 0;
ContentResolver resolver = context.getContentResolver();
try (InputStream is = new BufferedInputStream(resolver.openInputStream(uri))) {
VCardReader reader = new VCardReader(is);
InputStream is = resolver.openInputStream(uri);
if (is == null)
throw new FileNotFoundException(uri.toString());
try (InputStream bis = new BufferedInputStream(is)) {
VCardReader reader = new VCardReader(bis);
VCard vcard;
while ((vcard = reader.readNext()) != null) {
Integer type = null;
@@ -534,6 +537,8 @@ public class FragmentContacts extends FragmentBase {
ContentResolver resolver = context.getContentResolver();
try (OutputStream os = resolver.openOutputStream(uri)) {
if (os == null)
throw new FileNotFoundException(uri.toString());
try (VCardWriter writer = new VCardWriter(os, VCardVersion.V3_0)) {
for (VCard vcard : vcards)
writer.write(vcard);