Fix resource leaks in core file processing classes

- Add try-with-resources for FileInputStream in ZUGFeRDVisualizer
- Fix unclosed InputStream in ZUGFeRDInvoiceImporter with try-with-resources
- Add explicit close() call for XMLWriter in ZUGFeRDValidator
- Properly close DataInputStream in ZUGFeRDExporterFromPDFA
- Fix resource management in Main.convertInputStreamToString
This commit is contained in:
Ivan Pereverziev
2025-03-13 11:26:35 +01:00
parent 5e511acf3c
commit 7fa2d70128
6 changed files with 31 additions and 25 deletions

View File

@@ -131,8 +131,9 @@ public class ZUGFeRDVisualizer {
public String visualize(String xmlFilename, Language lang)
throws IOException, TransformerException, ParserConfigurationException {
FileInputStream fis = new FileInputStream(xmlFilename);
return visualize(fis, lang);
try (FileInputStream fis = new FileInputStream(xmlFilename)) {
return visualize(fis, lang);
}
}
public String visualize(InputStream inputXml, Language lang)
@@ -222,12 +223,14 @@ public class ZUGFeRDVisualizer {
protected String toFOP(String xmlFilename)
throws IOException, TransformerException, ParserConfigurationException {
FileInputStream fis = new FileInputStream(xmlFilename);
EStandard theStandard = findOutStandardFromRootNode(fis);
fis = new FileInputStream(xmlFilename);//rewind :-(
return toFOP(fis, theStandard);
EStandard theStandard;
try (FileInputStream fis = new FileInputStream(xmlFilename)) {
theStandard = findOutStandardFromRootNode(fis);
}
try (FileInputStream fis = new FileInputStream(xmlFilename)) {
return toFOP(fis, theStandard);
}
}
protected String toFOP(InputStream is, EStandard theStandard)