public static < T > T withWriter ( Writer writer , @ ClosureParams ( FirstParam . class ) Closure < T > closure ) throws IOException { try { T result = closure . call ( writer ) ; try { writer . flush ( ) ; } catch ( IOException e ) { // try to continue even in case of error } Writer temp = writer ; writer = null ; temp . close ( ) ; return result ; } finally { closeWithWarning ( writer ) ; } }
Allows this writer to be used within the closure ensuring that it is flushed and closed before this method returns .