Skip to content

Commit ce2da51

Browse files
committed
XMLTools: use try-with-resources statement
1 parent fae511d commit ce2da51

2 files changed

Lines changed: 5 additions & 25 deletions

File tree

src/main/java/loci/common/IniParser.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,10 @@ public IniList parseINI(String path, Class<?> c)
122122
public IniList parseINI(File file)
123123
throws IOException
124124
{
125-
FileInputStream fis = null;
126-
InputStreamReader isr = null;
127-
BufferedReader br = null;
128-
try {
129-
fis = new FileInputStream(file);
130-
isr = new InputStreamReader(fis, Constants.ENCODING);
131-
br = new BufferedReader(isr);
125+
try (FileInputStream fis = new FileInputStream(file);
126+
InputStreamReader isr = new InputStreamReader(fis, Constants.ENCODING);
127+
BufferedReader br = new BufferedReader(isr)) {
132128
return parseINI(br);
133-
} finally {
134-
if (br != null) {
135-
br.close();
136-
}
137-
if (isr != null) {
138-
isr.close();
139-
}
140-
if (fis != null) {
141-
fis.close();
142-
}
143129
}
144130
}
145131

src/main/java/loci/common/xml/XMLTools.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,9 @@ public static Document createDocument() {
189189
public static Document parseDOM(File file)
190190
throws ParserConfigurationException, SAXException, IOException
191191
{
192-
InputStream is = new FileInputStream(file);
193-
try {
192+
try (InputStream is = new FileInputStream(file)) {
194193
Document doc = parseDOM(is);
195194
return doc;
196-
} finally {
197-
is.close();
198195
}
199196
}
200197

@@ -211,12 +208,9 @@ public static Document parseDOM(String xml)
211208
throws ParserConfigurationException, SAXException, IOException
212209
{
213210
byte[] bytes = xml.getBytes(Constants.ENCODING);
214-
InputStream is = new ByteArrayInputStream(bytes);
215-
try {
211+
try (InputStream is = new ByteArrayInputStream(bytes)) {
216212
Document doc = parseDOM(is);
217213
return doc;
218-
} finally {
219-
is.close();
220214
}
221215
}
222216

0 commit comments

Comments
 (0)