Skip to content

Commit

Permalink
Fixed use of InputStream
Browse files Browse the repository at this point in the history
InputStream now closes after being used
  • Loading branch information
XSoussou committed Dec 2, 2020
1 parent 660de0b commit 4534333
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/me/soussou/chopchop/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package me.soussou.chopchop;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -87,7 +88,9 @@ private void checkUpdates() throws IOException, SAXException, ParserConfiguratio

private String getXmlVersion(URL url) throws IOException, SAXException, ParserConfigurationException {
String version = "";
Document pom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream());

InputStream in = url.openStream();
Document pom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
NodeList elements = pom.getFirstChild().getChildNodes(); // Every element of the main <project> node

for(int i = 0; i < elements.getLength(); i++) {
Expand All @@ -99,6 +102,8 @@ private String getXmlVersion(URL url) throws IOException, SAXException, ParserCo
}
}

in.close();

return version;
}

Expand Down

0 comments on commit 4534333

Please sign in to comment.