Groovy 2.2.1

org.codehaus.groovy.runtime
[Java] Class IOGroovyMethods

java.lang.Object
  org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
      org.codehaus.groovy.runtime.IOGroovyMethods

public class IOGroovyMethods
extends DefaultGroovyMethodsSupport

This class defines new groovy methods for Files, URLs, URIs which appear on normal JDK classes inside the Groovy environment. Static methods are used with the first parameter being the destination class, i.e. public static long size(File self) provides a size() method for File.

NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

Authors:
James Strachan
Jeremy Rayner
Sam Pullara
Rod Cope
Guillaume Laforge
John Wilson
Hein Meling
Dierk Koenig
Pilho Kim
Marc Guillemot
Russel Winder
bing ran
Jochen Theodorou
Paul King
Michael Baehr
Joachim Baumann
Alex Tkachman
Ted Naleid
Brad Long
Jim Jagielski
Rodolfo Velasco
jeremi Joslin
Hamlet D'Arcy
Cedric Champeau
Tim Yates
Dinko Srkoc


Method Summary
static void eachByte(InputStream is, Closure closure)

static void eachByte(InputStream is, int bufferLen, Closure closure)

static Object eachLine(InputStream stream, String charset, Closure closure)

Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure.

static Object eachLine(InputStream stream, String charset, int firstLine, Closure closure)

Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure.

static Object eachLine(InputStream stream, Closure closure)

Iterates through this stream, passing each line to the given 1 or 2 arg closure.

static Object eachLine(InputStream stream, int firstLine, Closure closure)

Iterates through this stream, passing each line to the given 1 or 2 arg closure.

static Object eachLine(Reader self, Closure closure)

Iterates through the given reader line by line.

static Object eachLine(Reader self, int firstLine, Closure closure)

Iterates through the given reader line by line.

static void eachObject(ObjectInputStream ois, Closure closure)

Iterates through the given object stream object by object.

static void filterLine(Reader reader, 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.

static Writable filterLine(Reader reader, Closure closure)

Filter the lines from this Reader, and return a Writable which can be used to stream the filtered lines to a destination.

static Writable filterLine(InputStream self, Closure predicate)

Filter lines from an input stream using a closure predicate.

static Writable filterLine(InputStream self, String charset, Closure predicate)

Uses a closure to filter lines from this InputStream and pass them to the given writer.

static void filterLine(InputStream self, Writer writer, Closure predicate)

Uses a closure to filter lines from this InputStream and pass them to the given writer.

static void filterLine(InputStream self, Writer writer, String charset, Closure predicate)

static byte[] getBytes(InputStream is)

Read the content of this InputStream and return it as a byte[].

static String getText(InputStream is)

Read the content of this InputStream using specified charset and return it as a String.

static String getText(InputStream is, String charset)

Read the content of the Reader and return it as a String.

static String getText(Reader reader)

Read the content of the BufferedReader and return it as a String.

static String getText(BufferedReader reader)

static Iterator iterator(Reader self)

static Iterator iterator(InputStream self)

Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.

static Iterator iterator(DataInputStream self)

static Writer leftShift(Writer self, Object value)

Overloads the leftShift operator for Writer to allow an object to be written using Groovy's default representation for the object.

static Appendable leftShift(Appendable self, Object value)

Overloads the leftShift operator for Appendable to allow an object to be appended using Groovy's default representation for the object.

static Writer leftShift(OutputStream self, Object value)

Overloads the leftShift operator to provide an append mechanism to add values to a stream.

static void leftShift(ObjectOutputStream self, Object value)

Overloads the leftShift operator to add objects to an ObjectOutputStream.

static OutputStream leftShift(OutputStream self, InputStream in)

Pipe an InputStream into an OutputStream for efficient stream copying.

static OutputStream leftShift(OutputStream self, byte[] value)

Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.

static ObjectInputStream newObjectInputStream(InputStream inputStream)

Create an object input stream for this input stream.

static ObjectInputStream newObjectInputStream(InputStream inputStream, ClassLoader classLoader)

Create an object input stream for this input stream using the given class loader.

static ObjectOutputStream newObjectOutputStream(OutputStream outputStream)

Create an object output stream for this output stream.

static PrintWriter newPrintWriter(Writer writer)

static PrintWriter newPrintWriter(OutputStream stream)

static BufferedReader newReader(InputStream self)

Creates a reader for this input stream.

static BufferedReader newReader(InputStream self, String charset)

static Writer newWriter(OutputStream stream)

static Writer newWriter(OutputStream stream, String charset)

static String readLine(Reader self)

Read a single, whole line from the given Reader.

static List readLines(InputStream stream)

Reads the stream into a list, with one element for each line.

static List readLines(InputStream stream, String charset)

Reads the reader into a list of Strings, with one entry for each line.

static List readLines(Reader reader)

Read the content of this InputStream and return it as a String.

static void setBytes(OutputStream os, byte[] bytes)

Write the text and append a newline (using the platform's line-ending).

static Object splitEachLine(Reader self, String regex, Closure closure)

Iterates through the given reader line by line, splitting each line using the given regex separator.

static Object splitEachLine(Reader self, Pattern pattern, Closure closure)

Iterates through the given reader line by line, splitting each line using the given regex separator Pattern.

static Object splitEachLine(InputStream stream, String regex, String charset, Closure closure)

Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator.

static Object splitEachLine(InputStream stream, Pattern pattern, String charset, Closure closure)

Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern.

static Object splitEachLine(InputStream stream, String regex, Closure closure)

Iterates through the given InputStream line by line, splitting each line using the given separator.

static Object splitEachLine(InputStream stream, Pattern pattern, Closure closure)

Iterates through the given InputStream line by line, splitting each line using the given separator Pattern.

static void transformChar(Reader self, Writer writer, Closure closure)

static void transformLine(Reader reader, Writer writer, Closure closure)

Transforms the lines from a reader with a Closure and write them to a writer.

static Appendable withFormatter(Appendable self, Closure closure)

Invokes a Closure that uses a Formatter taking care of resource handling.

static Appendable withFormatter(Appendable self, Locale locale, Closure closure)

Invokes a Closure that uses a Formatter taking care of resource handling.

static Object withObjectInputStream(InputStream inputStream, Closure closure)

Create a new ObjectInputStream for this file and pass it to the closure.

static Object withObjectInputStream(InputStream inputStream, ClassLoader classLoader, Closure closure)

Create a new ObjectInputStream for this file and pass it to the closure.

static Object withObjectOutputStream(OutputStream outputStream, Closure closure)

Create a new ObjectOutputStream for this output stream and then pass it to the closure.

static Object withPrintWriter(Writer writer, Closure closure)

static Object withPrintWriter(OutputStream stream, Closure closure)

static Object withReader(Reader reader, Closure closure)

static Object withReader(InputStream in, Closure closure)

Helper method to create a new Reader for a stream and then passes it into the closure.

static Object withReader(InputStream in, String charset, Closure closure)

Creates a writer from this stream, passing it to the given closure.

static Object withStream(InputStream stream, Closure closure)

static Object withStream(OutputStream os, Closure closure)

static Object withWriter(Writer writer, Closure closure)

static Object withWriter(OutputStream stream, Closure closure)

static Object withWriter(OutputStream stream, String charset, Closure closure)

static void write(Writer self, Writable writable)

A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface.

static void writeLine(BufferedWriter writer, String line)

Creates an iterator which will traverse through the reader a line at a time.

 
Methods inherited from class DefaultGroovyMethodsSupport
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

eachByte

public static void eachByte(InputStream is, Closure closure)


eachByte

public static void eachByte(InputStream is, int bufferLen, Closure closure)


eachLine

public static Object eachLine(InputStream stream, String charset, Closure closure)
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
stream - a stream
charset - opens the stream with a specified charset
closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
Returns:
the last value returned by the closure
See Also:
eachLine(java.io.InputStream, java.lang.String, int, groovy.lang.Closure)
Since:
1.5.5


eachLine

public static Object eachLine(InputStream stream, String charset, int firstLine, Closure closure)
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed after this method returns.
throws:
IOException if an IOException occurs.
Parameters:
stream - a stream
charset - opens the stream with a specified charset
firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
closure - a closure (arg 1 is line, optional arg 2 is line number)
Returns:
the last value returned by the closure
See Also:
eachLine(java.io.Reader, int, groovy.lang.Closure)
Since:
1.5.7


eachLine

public static Object eachLine(InputStream stream, Closure closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
stream - a stream
closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
Returns:
the last value returned by the closure
See Also:
eachLine(java.io.InputStream, int, groovy.lang.Closure)
Since:
1.5.6


eachLine

public static Object eachLine(InputStream stream, int firstLine, Closure closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
stream - a stream
firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
closure - a closure (arg 1 is line, optional arg 2 is line number)
Returns:
the last value returned by the closure
See Also:
eachLine(java.io.Reader, int, groovy.lang.Closure)
Since:
1.5.7


eachLine

public static Object eachLine(Reader self, Closure closure)
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.
throws:
IOException if an IOException occurs.
Parameters:
self - a Reader, closed after the method returns
closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
Returns:
the last value returned by the closure
See Also:
eachLine(java.io.Reader, int, groovy.lang.Closure)
Since:
1.5.6


eachLine

public static Object eachLine(Reader self, int firstLine, Closure closure)
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.
throws:
IOException if an IOException occurs.
Parameters:
self - a Reader, closed after the method returns
firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
closure - a closure which will be passed each line (or for 2 arg closures the line and line count)
Returns:
the last value returned by the closure
Since:
1.5.7


eachObject

public static void eachObject(ObjectInputStream ois, Closure closure)
Iterates through the given object stream object by object. The ObjectInputStream is closed afterwards.
throws:
IOException if an IOException occurs.
throws:
ClassNotFoundException if the class is not found.
Parameters:
ois - an ObjectInputStream, closed after the operation
closure - a closure
Since:
1.0


filterLine

public static void filterLine(Reader reader, 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.
throws:
IOException if an IOException occurs.
Parameters:
reader - a reader, closed after the call
writer - a writer, closed after the call
closure - the closure which returns booleans
Since:
1.0


filterLine

public static Writable filterLine(Reader reader, 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:
reader - this reader
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.
Since:
1.0


filterLine

public static Writable filterLine(InputStream self, Closure predicate)
Filter lines from an input stream using a closure predicate. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
Parameters:
self - an input stream
predicate - a closure which returns boolean and takes a line
Returns:
a writable which writes out the filtered lines
See Also:
filterLine(java.io.Reader, groovy.lang.Closure)
Since:
1.0


filterLine

public static Writable filterLine(InputStream self, String charset, Closure predicate)
Uses a closure to filter lines from this InputStream and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
throws:
IOException if an IOException occurs.
Parameters:
self - the InputStream
writer - a writer to write output to
predicate - a closure which returns true if a line should be accepted
See Also:
filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
Since:
1.0


filterLine

public static void filterLine(InputStream self, Writer writer, Closure predicate)
Uses a closure to filter lines from this InputStream and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
throws:
IOException if an IOException occurs.
Parameters:
self - the InputStream
writer - a writer to write output to
charset - opens the stream with a specified charset
predicate - a closure which returns true if a line should be accepted
See Also:
filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
Since:
1.6.8


filterLine

public static void filterLine(InputStream self, Writer writer, String charset, Closure predicate)


getBytes

public static byte[] getBytes(InputStream is)
Read the content of this InputStream and return it as a byte[]. The stream is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
is - an input stream
Returns:
the byte[] from that InputStream
Since:
1.7.1


getText

public static String getText(InputStream is)
Read the content of this InputStream using specified charset and return it as a String. The stream is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
is - an input stream
charset - opens the stream with a specified charset
Returns:
the text from that URL
Since:
1.0


getText

public static String getText(InputStream is, String charset)
Read the content of the Reader and return it as a String. The reader is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
reader - a Reader whose content we want to read
Returns:
a String containing the content of the buffered reader
See Also:
getText(java.io.BufferedReader)
Since:
1.0


getText

public static String getText(Reader reader)
Read the content of the BufferedReader and return it as a String. The BufferedReader is closed afterwards.
throws:
IOException if an IOException occurs.
Parameters:
reader - a BufferedReader whose content we want to read
Returns:
a String containing the content of the buffered reader
Since:
1.0


getText

public static String getText(BufferedReader reader)


iterator

public static Iterator iterator(Reader self)


iterator

public static Iterator iterator(InputStream self)
Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.
Parameters:
self - an InputStream object
Returns:
an Iterator for the InputStream
Since:
1.5.0


iterator

public static Iterator iterator(DataInputStream self)


leftShift

public static Writer leftShift(Writer self, Object value)
Overloads the leftShift operator for Writer to allow an object to be written using Groovy's default representation for the object.
throws:
IOException if an I/O error occurs.
Parameters:
self - a Writer
value - an Object whose default representation will be written to the Writer
Returns:
the writer on which this operation was invoked
Since:
1.0


leftShift

public static Appendable leftShift(Appendable self, Object value)
Overloads the leftShift operator for Appendable to allow an object to be appended using Groovy's default representation for the object.
throws:
IOException if an I/O error occurs.
Parameters:
self - an Appendable
value - an Object whose default representation will be appended to the Appendable
Returns:
the Appendable on which this operation was invoked
Since:
2.1.0


leftShift

public static Writer leftShift(OutputStream self, Object value)
Overloads the leftShift operator to provide an append mechanism to add values to a stream.
throws:
java.io.IOException if an I/O error occurs.
Parameters:
self - an OutputStream
value - a value to append
Returns:
a Writer
Since:
1.0


leftShift

public static void leftShift(ObjectOutputStream self, Object value)
Overloads the leftShift operator to add objects to an ObjectOutputStream.
throws:
IOException if an I/O error occurs.
Parameters:
self - an ObjectOutputStream
value - an object to write to the stream
Since:
1.5.0


leftShift

public static OutputStream leftShift(OutputStream self, InputStream in)
Pipe an InputStream into an OutputStream for efficient stream copying.
throws:
IOException if an I/O error occurs.
Parameters:
self - stream on which to write
in - stream to read from
Returns:
the outputstream itself
Since:
1.0


leftShift

public static OutputStream leftShift(OutputStream self, byte[] value)
Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.
throws:
IOException if an I/O error occurs.
Parameters:
self - an OutputStream
value - a value to append
Returns:
an OutputStream
Since:
1.0


newObjectInputStream

public static ObjectInputStream newObjectInputStream(InputStream inputStream)
Create an object input stream for this input stream.
throws:
IOException if an IOException occurs.
Parameters:
inputStream - an input stream
Returns:
an object input stream
Since:
1.5.0


newObjectInputStream

public static ObjectInputStream newObjectInputStream(InputStream inputStream, ClassLoader classLoader)
Create an object input stream for this input stream using the given class loader.
throws:
IOException if an IOException occurs.
Parameters:
inputStream - an input stream
classLoader - the class loader to use when loading the class
Returns:
an object input stream
Since:
1.5.0


newObjectOutputStream

public static ObjectOutputStream newObjectOutputStream(OutputStream outputStream)
Create an object output stream for this output stream.
throws:
IOException if an IOException occurs.
Parameters:
outputStream - an output stream
Returns:
an object output stream
Since:
1.5.0


newPrintWriter

public static PrintWriter newPrintWriter(Writer writer)


newPrintWriter

public static PrintWriter newPrintWriter(OutputStream stream)


newReader

public static BufferedReader newReader(InputStream self)
Creates a reader for this input stream.
Parameters:
self - an input stream
Returns:
a reader
Since:
1.0


newReader

public static BufferedReader newReader(InputStream self, String charset)


newWriter

public static Writer newWriter(OutputStream stream)


newWriter

public static Writer newWriter(OutputStream stream, String charset)


readLine

public static String readLine(Reader self)
Read a single, whole line from the given Reader.
throws:
IOException if an IOException occurs.
Parameters:
self - a Reader
Returns:
a line
Since:
1.0


readLines

public static List readLines(InputStream stream)
Reads the stream into a list, with one element for each line.
throws:
IOException if an IOException occurs.
Parameters:
stream - a stream
charset - opens the stream with a specified charset
Returns:
a List of lines
See Also:
readLines(java.io.Reader)
Since:
1.6.8


readLines

public static List readLines(InputStream stream, String charset)
Reads the reader into a list of Strings, with one entry for each line. The reader is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
reader - a Reader
Returns:
a List of lines
Since:
1.0


readLines

public static List readLines(Reader reader)
Read the content of this InputStream and return it as a String. The stream is closed before this method returns.
throws:
IOException if an IOException occurs.
Parameters:
is - an input stream
Returns:
the text from that URL
Since:
1.0


setBytes

public static void setBytes(OutputStream os, byte[] bytes)
Write the text and append a newline (using the platform's line-ending).
throws:
IOException if an IOException occurs.
Parameters:
writer - a BufferedWriter
line - the line to write
Since:
1.0


splitEachLine

public static Object splitEachLine(Reader self, String regex, Closure closure)
Iterates through the given reader line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. The Reader is closed afterwards.

Here is an example:

 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|'
 
throws:
IOException if an IOException occurs.
throws:
java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
Parameters:
self - a Reader, closed after the method returns
regex - the delimiting regular expression
closure - a closure
Returns:
the last value returned by the closure
See Also:
String.split
Since:
1.5.5


splitEachLine

public static Object splitEachLine(Reader self, Pattern pattern, Closure closure)
Iterates through the given reader line by line, splitting each line using the given regex separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. The Reader is closed afterwards.

Here is an example:

 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|'
 
throws:
IOException if an IOException occurs.
throws:
java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
Parameters:
self - a Reader, closed after the method returns
pattern - the regular expression Pattern for the delimiter
closure - a closure
Returns:
the last value returned by the closure
See Also:
String.split
Since:
1.6.8


splitEachLine

public static Object splitEachLine(InputStream stream, String regex, String charset, Closure closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. Finally, the stream is closed.
throws:
IOException if an IOException occurs.
throws:
java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
Parameters:
stream - an InputStream
regex - the delimiting regular expression
charset - opens the stream with a specified charset
closure - a closure
Returns:
the last value returned by the closure
See Also:
splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
Since:
1.5.5


splitEachLine

public static Object splitEachLine(InputStream stream, Pattern pattern, String charset, Closure closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure. Finally, the stream is closed.
throws:
IOException if an IOException occurs.
Parameters:
stream - an InputStream
pattern - the regular expression Pattern for the delimiter
charset - opens the stream with a specified charset
closure - a closure
Returns:
the last value returned by the closure
See Also:
splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
Since:
1.6.8


splitEachLine

public static Object splitEachLine(InputStream stream, String regex, Closure closure)
Iterates through the given InputStream 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 stream is closed before the method returns.
throws:
IOException if an IOException occurs.
throws:
java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
Parameters:
stream - an InputStream
regex - the delimiting regular expression
closure - a closure
Returns:
the last value returned by the closure
See Also:
splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
Since:
1.5.6


splitEachLine

public static Object splitEachLine(InputStream stream, Pattern pattern, Closure closure)
Iterates through the given InputStream line by line, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure. The stream is closed before the method returns.
throws:
IOException if an IOException occurs.
Parameters:
stream - an InputStream
pattern - the regular expression Pattern for the delimiter
closure - a closure
Returns:
the last value returned by the closure
See Also:
splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
Since:
1.6.8


transformChar

public static void transformChar(Reader self, Writer writer, Closure closure)


transformLine

public static void transformLine(Reader reader, 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.
throws:
IOException if an IOException occurs.
Parameters:
reader - Lines of text to be transformed. Reader is closed afterwards.
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.
Since:
1.0


withFormatter

public static Appendable withFormatter(Appendable self, Closure closure)
Invokes a Closure that uses a Formatter taking care of resource handling. A Formatter is created and passed to the Closure as its argument. After the Closure executes, the Formatter is flushed and closed releasing any associated resources.
Parameters:
self - an Appendable
closure - a 1-arg Closure which will be called with a Formatter as its argument
Returns:
the Appendable on which this operation was invoked
Since:
2.1.0


withFormatter

public static Appendable withFormatter(Appendable self, Locale locale, Closure closure)
Invokes a Closure that uses a Formatter taking care of resource handling. A Formatter is created using the given Locale and passed to the Closure as its argument. After the Closure executes, the Formatter is flushed and closed releasing any associated resources.
Parameters:
self - an Appendable
locale - a Locale used when creating the Formatter
closure - a 1-arg Closure which will be called with a Formatter as its argument
Returns:
the Appendable on which this operation was invoked
Since:
2.1.0


withObjectInputStream

public static Object withObjectInputStream(InputStream inputStream, Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
throws:
IOException if an IOException occurs.
Parameters:
inputStream - an input stream
closure - a closure
Returns:
the value returned by the closure
See Also:
withStream(java.io.InputStream, groovy.lang.Closure)
Since:
1.5.0


withObjectInputStream

public static Object withObjectInputStream(InputStream inputStream, ClassLoader classLoader, Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
throws:
IOException if an IOException occurs.
Parameters:
inputStream - an input stream
classLoader - the class loader to use when loading the class
closure - a closure
Returns:
the value returned by the closure
See Also:
withStream(java.io.InputStream, groovy.lang.Closure)
Since:
1.5.0


withObjectOutputStream

public static Object withObjectOutputStream(OutputStream outputStream, Closure closure)
Create a new ObjectOutputStream for this output stream and then pass it to the closure. This method ensures the stream is closed after the closure returns.
throws:
IOException if an IOException occurs.
Parameters:
outputStream - am output stream
closure - a closure
Returns:
the value returned by the closure
See Also:
withStream(java.io.OutputStream, groovy.lang.Closure)
Since:
1.5.0


withPrintWriter

public static Object withPrintWriter(Writer writer, Closure closure)


withPrintWriter

public static Object withPrintWriter(OutputStream stream, Closure closure)


withReader

public static Object withReader(Reader reader, Closure closure)


withReader

public static Object withReader(InputStream in, Closure closure)
Helper method to create a new Reader for a stream and then passes it into the closure. The reader (and this stream) is closed after the closure returns.
throws:
IOException if an IOException occurs.
Parameters:
in - a stream
charset - the charset used to decode the stream
closure - the closure to invoke with the reader
Returns:
the value returned by the closure
See Also:
InputStreamReader
Since:
1.5.6


withReader

public static Object withReader(InputStream in, String charset, Closure closure)
Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.
throws:
IOException if an IOException occurs.
Parameters:
stream - the stream which is used and then closed
closure - the closure that the writer is passed into
Returns:
the value returned by the closure
See Also:
withWriter(java.io.Writer, groovy.lang.Closure)
Since:
1.5.2


withStream

public static Object withStream(InputStream stream, Closure closure)


withStream

public static Object withStream(OutputStream os, Closure closure)


withWriter

public static Object withWriter(Writer writer, Closure closure)


withWriter

public static Object withWriter(OutputStream stream, Closure closure)


withWriter

public static Object withWriter(OutputStream stream, String charset, Closure closure)


write

public static void write(Writer self, Writable writable)
A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface.
throws:
IOException if an I/O error occurs.
Parameters:
self - a Writer
writable - an object implementing the Writable interface
Since:
1.0


writeLine

public static void writeLine(BufferedWriter writer, String line)
Creates an iterator which will traverse through the reader a line at a time.
Parameters:
self - a Reader object
Returns:
an Iterator for the Reader
See Also:
BufferedReader.readLine
Since:
1.5.0


 

Copyright © 2003-2013 The Codehaus. All rights reserved.