public static <T>T eachLine(Reader self,int firstLine,@ClosureParams(value=FromString.class,options={"String","String,Integer"}) Closure<T> closure) throws IOException {
  BufferedReader br;
  int count=firstLine;
  T result=null;
  if (self instanceof BufferedReader)   br=(BufferedReader)self;
 else   br=new BufferedReader(self);
  try {
    while (true) {
      String line=br.readLine();
      if (line == null) {
        break;
      }
 else {
        result=callClosureForLine(closure,line,count);
        count++;
      }
    }
    Reader temp=self;
    self=null;
    temp.close();
    return result;
  }
  finally {
    closeWithWarning(self);
    closeWithWarning(br);
  }
}

public static < T > T eachLine ( Reader self , int firstLine , @ ClosureParams ( value = FromString . class , options = { "String" , "String,Integer" } ) Closure < T > closure ) throws IOException { BufferedReader br ; int count = firstLine ; T result = null ; if ( self instanceof BufferedReader ) br = ( BufferedReader ) self ; else br = new BufferedReader ( self ) ; try { while ( true ) { String line = br . readLine ( ) ; if ( line == null ) { break ; } else { result = callClosureForLine ( closure , line , count ) ; count ++ ; } } Reader temp = self ; self = null ; temp . close ( ) ; return result ; } finally { closeWithWarning ( self ) ; closeWithWarning ( br ) ; } }
iterates through the given reader line by line . each line is passed to the given 1 or 2 arg closure . if the closure has two arguments , the line count is passed as the second argument . the reader is closed before this method returns .
