Skip to content

Commit 69622e4

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

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

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)