Skip to content

Commit

Permalink
more try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 24, 2024
1 parent ba08398 commit 8346df9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 1 addition & 4 deletions toolsrc/org/mozilla/javascript/tools/jsc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,8 @@ public void processSource(String[] filenames) {
byte[] bytes = (byte[]) compiled[j + 1];
try {
File outfile = getOutputFile(targetTopDir, className);
FileOutputStream os = new FileOutputStream(outfile);
try {
try (FileOutputStream os = new FileOutputStream(outfile)) {
os.write(bytes);
} finally {
os.close();
}
} catch (IOException ioe) {
addFormatedError(ioe.toString());
Expand Down
12 changes: 5 additions & 7 deletions toolsrc/org/mozilla/javascript/tools/shell/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -1034,14 +1034,12 @@ private static String readUrl(String filePath, String charCoding, boolean urlIsF
is = new FileInputStream(f);
}

Reader r;
if (charCoding == null) {
r = new InputStreamReader(is);
} else {
r = new InputStreamReader(is, charCoding);
try (Reader r =
new InputStreamReader(
is,
charCoding == null ? Charset.defaultCharset().name() : charCoding)) {
return readReader(r, chunkLength);
}
return readReader(r, chunkLength);

} finally {
if (is != null) is.close();
}
Expand Down

0 comments on commit 8346df9

Please sign in to comment.