protected void writeOpalConfig(Document opalConfig) { OutputStream outputStream = null; try { Source source = new DOMSource(opalConfig); File tmpFile = File.createTempFile("cfg", ".tmp"); Result dest = new StreamResult(outputStream = new FileOutputStream(tmpFile)); transformer.transform(source, dest); FileUtil.moveFile(tmpFile, new File(opalConfigFile)); } catch (IOException | TransformerException e) { throw new RuntimeException(e); } finally { StreamUtil.silentSafeClose(outputStream); } }