Messaging: Use try-with-resource
Change-Id: I6649517cbd990502dfcb54f078764cf05f210268
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -155,21 +156,13 @@ public class UriUtil {
|
||||
public static long getContentSize(final Uri uri) {
|
||||
Assert.isNotMainThread();
|
||||
if (isLocalResourceUri(uri)) {
|
||||
ParcelFileDescriptor pfd = null;
|
||||
try {
|
||||
pfd = Factory.get().getApplicationContext()
|
||||
.getContentResolver().openFileDescriptor(uri, "r");
|
||||
try (ParcelFileDescriptor pfd = Factory.get().getApplicationContext()
|
||||
.getContentResolver().openFileDescriptor(uri, "r")) {
|
||||
return Math.max(pfd.getStatSize(), 0);
|
||||
} catch (final FileNotFoundException e) {
|
||||
LogUtil.e(LogUtil.BUGLE_TAG, "Error getting content size", e);
|
||||
} finally {
|
||||
if (pfd != null) {
|
||||
try {
|
||||
pfd.close();
|
||||
} catch (final IOException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
} else {
|
||||
Assert.fail("Unsupported uri type!");
|
||||
|
||||
Reference in New Issue
Block a user