diff --git a/src/main/java/org/olat/core/util/mail/manager/MailManagerImpl.java b/src/main/java/org/olat/core/util/mail/manager/MailManagerImpl.java index 1c593e34cdbad8ce6f4720a437d19706f3175927..6cb68286719922c2d8c507d6eaeeb3649a3e4b97 100644 --- a/src/main/java/org/olat/core/util/mail/manager/MailManagerImpl.java +++ b/src/main/java/org/olat/core/util/mail/manager/MailManagerImpl.java @@ -595,14 +595,10 @@ public class MailManagerImpl extends BasicManager implements MailManager { File baseFolder = new File(WebappHelper.getUserDataRoot(), MAIL_TEMPLATE_FOLDER); File template = new File(baseFolder, "mail_template.html"); if(template.exists()) { - InputStream in = null; - try { - in = new FileInputStream(template); + try(InputStream in = new FileInputStream(template)) { return IOUtils.toString(in); } catch (IOException e) { logError("", e); - } finally { - IOUtils.closeQuietly(in); } } return getDefaultMailTemplate(); @@ -629,8 +625,7 @@ public class MailManagerImpl extends BasicManager implements MailManager { @Override public String getDefaultMailTemplate() { - try { - InputStream in = MailModule.class.getResourceAsStream("_content/mail_template.html"); + try(InputStream in = MailModule.class.getResourceAsStream("_content/mail_template.html")) { return IOUtils.toString(in); } catch (IOException e) { logError("Cannot read the default mail template", e); diff --git a/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java b/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java index f9080df655354bef520179641ebd3589b93c0966..ccbe64c27354f64c2f8a7ff3562d96ccf3bb338d 100644 --- a/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java +++ b/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java @@ -228,8 +228,7 @@ public class OpenXMLDocument { margins.setAttribute("w:gutter", "0"); if(StringHelper.containsNonWhitespace(documentHeader)) { - try { - InputStream headerIn = OpenXMLDocument.class.getResourceAsStream("_resources/header.xml"); + try(InputStream headerIn = OpenXMLDocument.class.getResourceAsStream("_resources/header.xml")) { String headerTemplate = IOUtils.toString(headerIn); String header = headerTemplate.replace("[oodocumentitlte]", documentHeader); diff --git a/src/main/java/org/olat/core/util/openxml/OpenXMLDocumentWriter.java b/src/main/java/org/olat/core/util/openxml/OpenXMLDocumentWriter.java index 39edc71df59e05c8cfc52f45d6a5446ea013c2c8..89d0697d6574f8efa74efb3571e42f3680c2186b 100644 --- a/src/main/java/org/olat/core/util/openxml/OpenXMLDocumentWriter.java +++ b/src/main/java/org/olat/core/util/openxml/OpenXMLDocumentWriter.java @@ -124,20 +124,21 @@ public class OpenXMLDocumentWriter { protected void appendMedias(ZipOutputStream out, OpenXMLDocument document) throws IOException { for(DocReference img:document.getImages()) { - FileInputStream in = new FileInputStream(img.getFile()); - ZipEntry wordDocument = new ZipEntry("word/media/" + img.getFile().getName()); - out.putNextEntry(wordDocument); - - IOUtils.copy(in, out); - OpenXMLUtils.writeTo(document.getDocument(), out, false); - out.closeEntry(); + try(FileInputStream in = new FileInputStream(img.getFile())) { + ZipEntry wordDocument = new ZipEntry("word/media/" + img.getFile().getName()); + out.putNextEntry(wordDocument); + + IOUtils.copy(in, out); + OpenXMLUtils.writeTo(document.getDocument(), out, false); + out.closeEntry(); + } catch(Exception e) { + log.error("", e); + } } } private void appendPredefinedStyles(ZipOutputStream out, OpenXMLStyles styles) { - InputStream in = null; - try { - in = OpenXMLDocumentWriter.class.getResourceAsStream("_resources/styles.xml"); + try(InputStream in = OpenXMLDocumentWriter.class.getResourceAsStream("_resources/styles.xml")) { if(styles != null) { Document stylesDoc = OpenXMLUtils.createDocument(in); NodeList stylesElList = stylesDoc.getElementsByTagName("w:styles"); @@ -151,8 +152,6 @@ public class OpenXMLDocumentWriter { } } catch (IOException e) { log.error("", e); - } finally { - IOUtils.closeQuietly(in); } } diff --git a/src/main/java/org/olat/ims/qti/render/LocalizedXSLTransformer.java b/src/main/java/org/olat/ims/qti/render/LocalizedXSLTransformer.java index 312611c27c480fa9568dbab0703d160052768804..ad63654040378bb2fcc7e3677b57bfab20abf7a1 100644 --- a/src/main/java/org/olat/ims/qti/render/LocalizedXSLTransformer.java +++ b/src/main/java/org/olat/ims/qti/render/LocalizedXSLTransformer.java @@ -173,14 +173,12 @@ public class LocalizedXSLTransformer { * Helper to create XSLT transformer for this instance */ private void initTransformer() { - // build new transformer - InputStream xslin = getClass().getResourceAsStream("/org/olat/ims/resources/xsl/" + XSLFILENAME); // translate xsl with velocity Context vcContext = new VelocityContext(); vcContext.put("t", pT); vcContext.put("staticPath", StaticMediaDispatcher.createStaticURIFor("")); String xslAsString = ""; - try { + try(InputStream xslin = getClass().getResourceAsStream("/org/olat/ims/resources/xsl/" + XSLFILENAME)) { xslAsString = slurp(xslin); } catch (IOException e) { log.error("Could not convert xsl to string!", e);