|
Groovy JDK | |||||||||
| Method Summary | |
|---|---|
Object
|
eachLine(Closure closure)
Iterates through the given reader line by line. |
Object
|
eachLine(int firstLine, Closure closure)
Iterates through the given reader line by line. |
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. |
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. |
String
|
getText()
Read the content of the Reader and return it as a String. |
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. |
Object
|
splitEachLine(String regex, Closure closure)
Iterates through the given reader line by line, splitting each line using the given regex separator. |
void
|
transformChar(Writer writer, Closure closure)
Transforms each character from this reader by passing it to the given closure. |
void
|
transformLine(Writer writer, Closure closure)
Transforms the lines from a reader with a Closure and write them to a writer. |
Object
|
withReader(Closure closure)
Allows this reader to be used within the closure, ensuring that it is closed before this method returns. |
| Method Detail |
|---|
public Object eachLine(Closure closure)
closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1).public Object eachLine(int firstLine, Closure closure)
firstLine - the count of the first line.closure - a closure which will be passed each line (or for 2 arg closures the line and line count).public void filterLine(Writer writer, Closure closure)
writer - a writer, closed after the call.closure - the closure which returns booleans.public Writable filterLine(Closure closure)
true if the line should be passed to the writer.closure - a closure used for filtering.public String getText()
public Iterator iterator()
public String readLine()
public List readLines()
public Object splitEachLine(String regex, Closure closure)
def s = 'The 3 quick\nbrown 4 fox'
def result = ''
new StringReader(s).splitEachLine(/\d/){ parts ->
result += "${parts[0]}_${parts[1]}|"
}
assert result == 'The _ quick|brown _ fox|'
regex - the delimiting regular expression.closure - a closure.public void transformChar(Writer writer, Closure closure)
writer - a Writer to receive the transformed characters.closure - a closure that performs the required transformation.public void transformLine(Writer writer, Closure closure)
writer - Where transformed lines are written. Writer is closed afterwards..closure
- Single parameter closure that is called to transform each line of
text from the reader, before writing it to the writer..public Object withReader(Closure closure)
closure - the closure that the writer is passed into.
|
Groovy JDK | |||||||||