@ Override @ DoesServiceRequest public void close ( ) throws IOException { try { // if the user has already closed the stream, this will throw a STREAM_CLOSED exception // if an exception was thrown by any thread in the threadExecutor, realize it now this . checkStreamState ( ) ; // flush any remaining data this . flush ( ) ; // shut down the ExecutorService. this . threadExecutor . shutdown ( ) ; // try to commit the file try { this . commit ( ) ; } catch ( final StorageException e ) { throw Utility . initIOException ( e ) ; } catch ( URISyntaxException e ) { throw Utility . initIOException ( e ) ; } } finally { // if close() is called again, an exception will be thrown synchronized ( this . lastErrorLock ) { this . streamFaulted = true ; this . lastError = new IOException ( SR . STREAM_CLOSED ) ; } // if an exception was thrown and the executor was not yet closed, call shutDownNow() to cancel all tasks // and shutdown the ExecutorService if ( ! this . threadExecutor . isShutdown ( ) ) { this . threadExecutor . shutdownNow ( ) ; } } }
Closes this output stream and releases any system resources associated with this stream . If any data remains in the buffer it is committed to the service .