public static < T , U extends Closeable > T withCloseable ( U self , @ ClosureParams ( value = FirstParam . class ) Closure < T > action ) throws IOException { try { T result = action . call ( self ) ; Closeable temp = self ; self = null ; temp . close ( ) ; return result ; } finally { DefaultGroovyMethodsSupport . closeWithWarning ( self ) ; } }
Allows this closeable to be used within the closure ensuring that it is closed once the closure has been executed and before this method returns .