public static void transformLine ( Reader reader , Writer writer , @ ClosureParams ( value = SimpleType . class , options = "java.lang.String" ) Closure closure ) throws IOException { BufferedReader br = new BufferedReader ( reader ) ; BufferedWriter bw = new BufferedWriter ( writer ) ; String line ; try { while ( ( line = br . readLine ( ) ) != null ) { Object o = closure . call ( line ) ; if ( o != null ) { bw . write ( o . toString ( ) ) ; bw . newLine ( ) ; } } bw . flush ( ) ; Writer temp2 = writer ; writer = null ; temp2 . close ( ) ; Reader temp1 = reader ; reader = null ; temp1 . close ( ) ; } finally { closeWithWarning ( br ) ; closeWithWarning ( reader ) ; closeWithWarning ( bw ) ; closeWithWarning ( writer ) ; } }
Transforms the lines from a reader with a Closure and write them to a writer . Both Reader and Writer are closed after the operation .