Skip to content

Instantly share code, notes, and snippets.

@wytten
Created October 28, 2013 17:19
Show Gist options
  • Select an option

  • Save wytten/7200849 to your computer and use it in GitHub Desktop.

Select an option

Save wytten/7200849 to your computer and use it in GitHub Desktop.
Add a method to File class: A variation of eachLine that accepts a stopClosure
/*
* Add a method to File class: A variation of eachLine that accepts a stopClosure
*/
File.metaClass.eachLineBreak = { stopClosure, workClosure ->
for (Iterator iter = delegate.iterator(); iter.hasNext();) {
def value = iter.next()
if (stopClosure.call(value)) {
break
} else {
workClosure.call(value)
}
}
}
/*
* STOP_CONDITION can be used to limit the processing for testing purposes
*/
//def STOP_CONDITION = { false }
def STOP_CONDITION = { retriever.getQueryFoundCount() == 10000 }
def count = 0
long start = System.currentTimeMillis()
new File(FILENAME).eachLineBreak( STOP_CONDITION ) {
count++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment