Skip to content

Commit 201eb61

Browse files
committed
Close XMLStreamWriter
1 parent abe16cb commit 201eb61

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v2/XmlConfigurationMapper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public ConfigurationNode parse(InputStream inputStream) throws IOException {
7878

7979
@Override
8080
public void writeConfiguration(OutputStream outputStream, ConfigurationNode configuration) throws IOException {
81+
XMLStreamWriter streamWriter = createStreamWriter(outputStream);
8182
try {
82-
XMLStreamWriter streamWriter = createStreamWriter(outputStream);
8383
streamWriter.writeStartDocument();
8484
streamWriter.setDefaultNamespace(LOG4J_NAMESPACE_URI);
8585
streamWriter.writeStartElement(LOG4J_NAMESPACE_URI, configuration.getPluginName());
@@ -92,8 +92,19 @@ public void writeConfiguration(OutputStream outputStream, ConfigurationNode conf
9292
writeNodeContentToStreamWriter(configuration, streamWriter);
9393
streamWriter.writeEndElement();
9494
streamWriter.writeEndDocument();
95+
streamWriter.flush();
9596
} catch (XMLStreamException e) {
9697
throw new IOException("Unable to write configuration.", e);
98+
} finally {
99+
closeStreamWriter(streamWriter);
100+
}
101+
}
102+
103+
private static void closeStreamWriter(XMLStreamWriter streamWriter) throws IOException {
104+
try {
105+
streamWriter.close();
106+
} catch (XMLStreamException e) {
107+
throw new IOException("Unable to close stream writer.", e);
97108
}
98109
}
99110

0 commit comments

Comments
 (0)