Merge pull request #776 from W25X80/feature_resource_leaks
Fix potential resource leaks in core file processing classes
This commit is contained in:
@@ -220,7 +220,8 @@ public class XMLTools extends XMLWriter {
|
||||
}
|
||||
|
||||
public static byte[] getBytesFromStream(InputStream fileinput) throws IOException {
|
||||
return IOUtils.toByteArray (fileinput);
|
||||
// Stream closing responsibility is with the caller
|
||||
return IOUtils.toByteArray(fileinput);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -90,9 +90,10 @@ public class ZUGFeRDExporterFromPDFA implements IZUGFeRDExporter {
|
||||
|
||||
protected byte[] inputstreamToByteArray(InputStream fileInputStream) throws IOException {
|
||||
byte[] bytes = new byte[fileInputStream.available()];
|
||||
DataInputStream dataInputStream = new DataInputStream(fileInputStream);
|
||||
dataInputStream.readFully(bytes);
|
||||
return bytes;
|
||||
try (DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
|
||||
dataInputStream.readFully(bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
@@ -138,9 +138,9 @@ public class ZUGFeRDInvoiceImporter {
|
||||
return;
|
||||
}
|
||||
|
||||
final InputStream XMP = doc.getDocumentCatalog().getMetadata().exportXMPMetadata();
|
||||
|
||||
xmpString = new String(XMLTools.getBytesFromStream(XMP), StandardCharsets.UTF_8);
|
||||
try (final InputStream XMP = doc.getDocumentCatalog().getMetadata().exportXMPMetadata()) {
|
||||
xmpString = new String(XMLTools.getBytesFromStream(XMP), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
final PDEmbeddedFilesNameTreeNode etn = names.getEmbeddedFiles();
|
||||
if (etn == null) {
|
||||
|
||||
@@ -142,8 +142,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)
|
||||
@@ -233,12 +234,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)
|
||||
|
||||
Reference in New Issue
Block a user