Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2024-01-22 16:32:35 +0300
committerStefan Niedermann <info@niedermann.it>2024-01-22 16:32:35 +0300
commite285116a85586cc5f4c4d306e18dd83240e17aa7 (patch)
treea45811a483b5d2d8ee9425c2350470c4f630888d
parent2a6872d25b05d4b600d2e01e7257d506560a9439 (diff)
chore(lint): Use try-with-resources
Signed-off-by: Stefan Niedermann <info@niedermann.it>
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java25
1 files changed, 14 insertions, 11 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java
index 2e4bb9406..07076d17e 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java
@@ -29,17 +29,20 @@ public class FilesUtil {
*/
@WorkerThread
public static File copyContentUriToTempFile(@NonNull Context context, @NonNull Uri currentUri, long accountId, Long localCardId) throws IOException, IllegalArgumentException {
- final var inputStream = context.getContentResolver().openInputStream(currentUri);
- if (inputStream == null) {
- throw new IOException("Could not open input stream for " + currentUri.getPath());
- }
- final var cacheFile = getTempCacheFile(context, "attachments/account-" + accountId + "/card-" + (localCardId == null ? "pending-creation" : localCardId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context));
- final var outputStream = new FileOutputStream(cacheFile);
- byte[] buffer = new byte[4096];
-
- int count;
- while ((count = inputStream.read(buffer)) > 0) {
- outputStream.write(buffer, 0, count);
+ final File cacheFile;
+ try (var inputStream = context.getContentResolver().openInputStream(currentUri)) {
+ if (inputStream == null) {
+ throw new IOException("Could not open input stream for " + currentUri.getPath());
+ }
+ cacheFile = getTempCacheFile(context, "attachments/account-" + accountId + "/card-" + (localCardId == null ? "pending-creation" : localCardId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context));
+ try (var outputStream = new FileOutputStream(cacheFile)) {
+ byte[] buffer = new byte[4096];
+
+ int count;
+ while ((count = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, count);
+ }
+ }
}
DeckLog.verbose("----- wrote");
return cacheFile;