Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328943

Summary: Writer is never closed when using URIConverter.Writeable
Product: [Modeling] EMF Reporter: Bryan Hunt <bhunt>
Component: XML/XMIAssignee: Ed Merks <Ed.Merks>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 2.6.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Bryan Hunt CLA 2010-10-28 11:50:20 EDT
I'm using a URIHandler to create an instance of URIConverter.Writable.  I'm supplying my own extension of Writer so that I can intercept the close() call in order to close a database connection.  The close() function is never called.

I've worked around the problem by calling close() when flush() is called.  This will get me by, but is very dangerous.

FYI, I do not see this problem when using URIConverter.Readable.  The close() function on the Reader is properly called.
Comment 1 Bryan Hunt CLA 2010-10-28 12:46:59 EDT
I found a better workaround by extending XMIResourceImpl and closing the writer in doSave().
Comment 2 Ed Merks CLA 2010-10-28 17:37:32 EDT
WritableOutputStream has

    public void close() throws IOException
    {
      super.close();
      writer.close();
    }
    
so I think the writer is closed when the stream is closed.

Note that when you call Resource.save(OutputStream, Map<Object, Object>) you created the stream and you're responsible for closing it.  Only when the Resource itself opens a stream does it close the stream.  After all, you may passing System.out and you'd not want that closed...

Or did I miss something?