Skip to content

Commit 4c33c33

Browse files
author
anton.bashirov
committed
fix streams closing
1 parent 108737e commit 4c33c33

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

application-core/src/main/java/ru/art/core/extension/InputOutputStreamExtensions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import lombok.experimental.*;
2222
import static ru.art.core.constants.BufferConstants.*;
23-
import static ru.art.core.constants.StreamConstants.*;
2423
import static ru.art.core.extension.InputStreamExtensions.*;
2524
import java.io.*;
2625

application-xml/src/main/java/ru/art/xml/descriptor/XmlEntityWriter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static ru.art.core.constants.StringConstants.*;
2929
import static ru.art.core.context.Context.*;
3030
import static ru.art.core.extension.FileExtensions.*;
31+
import static ru.art.logging.LoggingModule.*;
3132
import static ru.art.xml.constants.XmlDocumentConstants.*;
3233
import static ru.art.xml.constants.XmlMappingExceptionMessages.*;
3334
import static ru.art.xml.module.XmlModule.*;
@@ -71,18 +72,26 @@ public static String writeXml(XMLOutputFactory xmlOutputFactory, XmlEntity xmlEn
7172
return outputStream.toString();
7273
} catch (Throwable throwable) {
7374
throw new XmlMappingException(throwable);
75+
} finally {
76+
if (nonNull(xmlStreamWriter)) {
77+
try {
78+
xmlStreamWriter.close();
79+
} catch (Throwable throwable) {
80+
loggingModule()
81+
.getLogger(XmlEntityWriter.class)
82+
.error(throwable.getMessage(), throwable);
83+
}
84+
}
7485
}
7586
}
7687

77-
7888
private static void writeAllElements(XMLStreamWriter xmlStreamWriter, XmlEntity xmlEntity) throws XMLStreamException {
7989
writeStartDocument(xmlStreamWriter);
8090
writeXmlEntity(xmlStreamWriter, xmlEntity);
8191
writeEndDocument(xmlStreamWriter);
8292
}
8393

8494
private static void writeXmlEntity(XMLStreamWriter xmlStreamWriter, XmlEntity entity) throws XMLStreamException {
85-
//gather all child elements
8695
List<XmlEntity> children = entity.getChildren();
8796

8897
if (isEmpty(children) && isEmpty(entity.getValue())) return;
@@ -99,7 +108,6 @@ private static void writeXmlEntity(XMLStreamWriter xmlStreamWriter, XmlEntity en
99108
writeNamespaces(xmlStreamWriter, entity);
100109
writeAttributes(xmlStreamWriter, entity);
101110

102-
//gather elements sequence
103111
for (XmlEntity xmlEntity : children) {
104112
if (isEmpty(xmlEntity)) continue;
105113
writeXmlEntity(xmlStreamWriter, xmlEntity);

0 commit comments

Comments
 (0)