Skip to content

Commit

Permalink
Use try with resources
Browse files Browse the repository at this point in the history
  • Loading branch information
twogee committed Dec 15, 2019
1 parent c1b7a55 commit fa75a7c
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ public final Properties getProperties(final String key) {
*/
@Override
public void load() throws IOException {
FileInputStream is = null;
try {
is = new FileInputStream(prefFile);
try (FileInputStream is = new FileInputStream(prefFile)) {
final DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setIgnoringElementContentWhitespace(true);
Expand Down Expand Up @@ -376,10 +374,6 @@ public void addProperties(final String k, final Element element) {
};

loadProperties(rootElement, loader);
} finally {
if (is != null) {
is.close();
}
}
}

Expand All @@ -390,9 +384,7 @@ public void addProperties(final String k, final Element element) {
*/
@Override
public void save() throws IOException {
FileOutputStream os = null;
try {
os = new FileOutputStream(prefFile);
try (FileOutputStream os = new FileOutputStream(prefFile)) {
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
Expand Down Expand Up @@ -466,10 +458,6 @@ public boolean needSaving(final String key) {
LOG.error("Cannot save preferences", e);
throw new IOException("Cannot save preferences", e);
}
} finally {
if (os != null) {
os.close();
}
}
}

Expand Down

0 comments on commit fa75a7c

Please sign in to comment.