Groovy JDK

java.io
Class Reader

Method Summary
Object eachLine(Closure closure)
Iterates through the given reader line by line to the given closure
void filterLine(Writer writer, Closure closure)
Filter the lines from a reader and write them on the writer, according to a closure which returns true if the line should be included Both Reader and Writer are closed after the operation
Writable filterLine(Closure closure)
Filter the lines from this Reader, and return a Writable which can be used to stream the filtered lines to a destination return true if the line should be passed to the writer
String getText()
Read the content of the Reader and return it as a String is closed before this method returns
Iterator iterator()
Creates an iterator which will traverse through the reader a line at a time
String readLine()
Read a single, whole line from the given Reader
List readLines()
Reads the reader into a list of Strings, with one entry for each line The reader is closed before this method returns
Object splitEachLine(String sep, Closure closure)
Iterates through the given reader line by line, splitting each line using the given separator the given closure
void transformChar(Writer writer, Closure closure)
Transforms each character from this reader by passing it to the given closure will be passed to the Writer closed before this method returns
void transformLine(Writer writer, Closure closure)
Transforms the lines from a reader with a Closure and write them to a writer closed after the operation
Object withReader(Closure closure)
Allows this reader to be used within the closure, ensuring that it is closed before this method returns
 
Method Detail

eachLine

public Object eachLine(Closure closure)
Iterates through the given reader line by line. Each line is passed to the given closure. The Reader is closed before this method returns.

Parameters:
closure - a closure.
Returns:
the last value returned by the closure

filterLine

public void filterLine(Writer writer, Closure closure)
Filter the lines from a reader and write them on the writer, according to a closure which returns true if the line should be included. Both Reader and Writer are closed after the operation.

Parameters:
writer - a writer, closed after the call.
closure - the closure which returns booleans.

filterLine

public Writable filterLine(Closure closure)
Filter the lines from this Reader, and return a Writable which can be used to stream the filtered lines to a destination. The closure should return true if the line should be passed to the writer.

Parameters:
closure - a closure used for filtering.
Returns:
a Writable which will use the closure to filter each line from the reader when the Writable#writeTo(Writer) is called.

getText

public String getText()
Read the content of the Reader and return it as a String. The reader is closed before this method returns.

Returns:
a String containing the content of the buffered reader
See:
#getText(BufferedReader).

iterator

public Iterator iterator()
Creates an iterator which will traverse through the reader a line at a time.

Returns:
an Iterator for the Reader
See:
BufferedReader#readLine.

readLine

public String readLine()
Read a single, whole line from the given Reader.

Returns:
a line

readLines

public List readLines()
Reads the reader into a list of Strings, with one entry for each line. The reader is closed before this method returns.

Returns:
a List of lines

splitEachLine

public Object splitEachLine(String sep, Closure closure)
Iterates through the given reader line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. The Reader is closed afterwards.

Parameters:
sep - a String separator.
closure - a closure.
Returns:
the last value returned by the closure
See:
String#split(String).

transformChar

public void transformChar(Writer writer, Closure closure)
Transforms each character from this reader by passing it to the given closure. The Closure should return each transformed character, which will be passed to the Writer. The reader and writer will be both be closed before this method returns.

Parameters:
writer - a Writer to receive the transformed characters.
closure - a closure that performs the required transformation.

transformLine

public void transformLine(Writer writer, Closure closure)
Transforms the lines from a reader with a Closure and write them to a writer. Both Reader and Writer are closed after the operation.

Parameters:
writer - Where transformed lines are written. Writer is closed afterwards..
closure text - Single parameter closure that is called to transform each line of text from the reader, before writing it to the writer..

withReader

public Object withReader(Closure closure)
Allows this reader to be used within the closure, ensuring that it is closed before this method returns.

Parameters:
closure - the closure that the writer is passed into.
Returns:
the value returned by the closure

Groovy JDK