Skip to content

Commit

Permalink
Simplify nested try-with-resources statements (flutter#7239)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvolkert authored Dec 18, 2018
1 parent 42c62a9 commit 951edf3
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions shell/platform/android/io/flutter/view/ResourceExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,19 @@ private boolean extractAPK(File dataDir) {
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) {
Expand Down Expand Up @@ -158,21 +157,20 @@ private boolean extractUpdate(File dataDir) {
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);
}
try (InputStream is = zipFile.getInputStream(entry);
OutputStream os = new FileOutputStream(output)) {
if (buffer == null) {
buffer = new byte[BUFFER_SIZE];
}

os.flush();
Log.i(TAG, "Extracted override resource " + asset);
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;

Expand Down

0 comments on commit 951edf3

Please sign in to comment.