Skip to content

Commit

Permalink
MacGenerator: close InputStream after use
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jun 14, 2023
1 parent dd52936 commit f1d2746
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -946,17 +946,27 @@ public void setSelectorEnum(String selectorEnumName) {
}

Document getDocument(String xmlPath) {
try {
InputStream is = null;
if (xmlPath.indexOf(File.separatorChar) == -1) is = getClass().getResourceAsStream(xmlPath);
if (is == null) is = new BufferedInputStream(new FileInputStream(xmlPath));
if (is != null) return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(is));
try (InputStream is = createInputStream(xmlPath)) {
if (is != null) {
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(is));
}
} catch (Exception e) {
// e.printStackTrace();
//ignored
}
return null;
}

private InputStream createInputStream(String xmlPath) throws FileNotFoundException {
InputStream is = null;
if (xmlPath.indexOf(File.separatorChar) == -1) {
is = getClass().getResourceAsStream(xmlPath); // null if noresource is found
}
if (is == null) {
is = new BufferedInputStream(new FileInputStream(xmlPath));
}
return is;
}

public String[] getExtraAttributeNames(Node node) {
String name = node.getNodeName();
if (name.equals("method")) {
Expand Down

0 comments on commit f1d2746

Please sign in to comment.