Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do StAX readers and writers not close the underlying input source? [closed]

Tags:

java

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?

like image 844
Evgeniy Dorofeev Avatar asked May 11 '13 05:05

Evgeniy Dorofeev


1 Answers

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.

like image 53
JB Nizet Avatar answered Sep 30 '22 15:09

JB Nizet