From 2d383262d7435474d811b8472f1051562784e90f Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Mon, 17 Dec 2018 16:34:54 -0800 Subject: [PATCH] Simplify nested try-with-resources statements (flutter/engine#7239) --- .../io/flutter/view/ResourceExtractor.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java index 67fc1aa19e..fd7d148be9 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java @@ -87,20 +87,19 @@ class ResourceExtractor { output.getParentFile().mkdirs(); } - try (InputStream is = manager.open(asset)) { - try (OutputStream os = new FileOutputStream(output)) { - if (buffer == null) { - buffer = new byte[BUFFER_SIZE]; - } - - int count = 0; - while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) { - os.write(buffer, 0, count); - } - - os.flush(); - Log.i(TAG, "Extracted baseline resource " + asset); + try (InputStream is = manager.open(asset); + OutputStream os = new FileOutputStream(output)) { + if (buffer == null) { + buffer = new byte[BUFFER_SIZE]; } + + int count = 0; + while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) { + os.write(buffer, 0, count); + } + + os.flush(); + Log.i(TAG, "Extracted baseline resource " + asset); } } catch (FileNotFoundException fnfe) { @@ -158,21 +157,20 @@ class ResourceExtractor { output.getParentFile().mkdirs(); } - try (InputStream is = zipFile.getInputStream(entry)) { - try (OutputStream os = new FileOutputStream(output)) { - if (buffer == null) { - buffer = new byte[BUFFER_SIZE]; - } - - int count = 0; - while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) { - os.write(buffer, 0, count); - } - - os.flush(); - Log.i(TAG, "Extracted override resource " + asset); + try (InputStream is = zipFile.getInputStream(entry); + OutputStream os = new FileOutputStream(output)) { + if (buffer == null) { + buffer = new byte[BUFFER_SIZE]; } + int count = 0; + while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) { + os.write(buffer, 0, count); + } + + os.flush(); + Log.i(TAG, "Extracted override resource " + asset); + } catch (FileNotFoundException fnfe) { continue;