28
28
import static ru .art .core .constants .StringConstants .*;
29
29
import static ru .art .core .context .Context .*;
30
30
import static ru .art .core .extension .FileExtensions .*;
31
+ import static ru .art .logging .LoggingModule .*;
31
32
import static ru .art .xml .constants .XmlDocumentConstants .*;
32
33
import static ru .art .xml .constants .XmlMappingExceptionMessages .*;
33
34
import static ru .art .xml .module .XmlModule .*;
@@ -71,18 +72,26 @@ public static String writeXml(XMLOutputFactory xmlOutputFactory, XmlEntity xmlEn
71
72
return outputStream .toString ();
72
73
} catch (Throwable throwable ) {
73
74
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
+ }
74
85
}
75
86
}
76
87
77
-
78
88
private static void writeAllElements (XMLStreamWriter xmlStreamWriter , XmlEntity xmlEntity ) throws XMLStreamException {
79
89
writeStartDocument (xmlStreamWriter );
80
90
writeXmlEntity (xmlStreamWriter , xmlEntity );
81
91
writeEndDocument (xmlStreamWriter );
82
92
}
83
93
84
94
private static void writeXmlEntity (XMLStreamWriter xmlStreamWriter , XmlEntity entity ) throws XMLStreamException {
85
- //gather all child elements
86
95
List <XmlEntity > children = entity .getChildren ();
87
96
88
97
if (isEmpty (children ) && isEmpty (entity .getValue ())) return ;
@@ -99,7 +108,6 @@ private static void writeXmlEntity(XMLStreamWriter xmlStreamWriter, XmlEntity en
99
108
writeNamespaces (xmlStreamWriter , entity );
100
109
writeAttributes (xmlStreamWriter , entity );
101
110
102
- //gather elements sequence
103
111
for (XmlEntity xmlEntity : children ) {
104
112
if (isEmpty (xmlEntity )) continue ;
105
113
writeXmlEntity (xmlStreamWriter , xmlEntity );
0 commit comments