According to StAX XMLEventReader, XMLEventWriter, XMLStreamReader, XMLStreamWriter API close() method does not close the uderlying resource. Thus this code
XMLInputFactory xf = XMLInputFactory.newInstance();
XMLStreamReader xr = xf.createXMLStreamReader(new FileInputStream("1.xml"));
...
xr.close();
which seems safe at first glance results in a resource leak.
Does anybody know a use case when not closing the underlying resource could be useful?
What comes to mind is socket-based communication, where several XML documents are sent and received, and closing the underlying stream would close the socket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With