public class IOGroovyMethods extends DefaultGroovyMethodsSupport
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.
DefaultGroovyMethodsSupport.RangeInfo
Constructor and Description |
---|
IOGroovyMethods() |
Modifier and Type | Method and Description |
---|---|
static void |
eachByte(java.io.InputStream is,
Closure closure)
Traverse through each byte of the specified stream.
|
static void |
eachByte(java.io.InputStream is,
int bufferLen,
Closure closure)
Traverse through each the specified stream reading bytes into a buffer
and calling the 2 parameter closure with this buffer and the number of bytes.
|
static <T> T |
eachLine(java.io.InputStream stream,
Closure<T> closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure.
|
static <T> T |
eachLine(java.io.InputStream stream,
int firstLine,
Closure<T> closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure.
|
static <T> T |
eachLine(java.io.InputStream stream,
java.lang.String charset,
Closure<T> closure)
Iterates through this stream reading with the provided charset, passing each line to the
given 1 or 2 arg closure.
|
static <T> T |
eachLine(java.io.InputStream stream,
java.lang.String charset,
int firstLine,
Closure<T> closure)
Iterates through this stream reading with the provided charset, passing each line to
the given 1 or 2 arg closure.
|
static <T> T |
eachLine(java.io.Reader self,
Closure<T> closure)
Iterates through the given reader line by line.
|
static <T> T |
eachLine(java.io.Reader self,
int firstLine,
Closure<T> closure)
Iterates through the given reader line by line.
|
static void |
eachObject(java.io.ObjectInputStream ois,
Closure closure)
Iterates through the given object stream object by object.
|
static Writable |
filterLine(java.io.InputStream self,
Closure predicate)
Filter lines from an input stream using a closure predicate.
|
static Writable |
filterLine(java.io.InputStream self,
java.lang.String charset,
Closure predicate)
Filter lines from an input stream using a closure predicate.
|
static void |
filterLine(java.io.InputStream self,
java.io.Writer writer,
Closure predicate)
Uses a closure to filter lines from this InputStream and pass them to
the given writer.
|
static void |
filterLine(java.io.InputStream self,
java.io.Writer writer,
java.lang.String charset,
Closure predicate)
Uses a closure to filter lines from this InputStream and pass them to
the given writer.
|
static Writable |
filterLine(java.io.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 void |
filterLine(java.io.Reader reader,
java.io.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 byte[] |
getBytes(java.io.InputStream is)
Read the content of this InputStream and return it as a byte[].
|
static java.lang.String |
getText(java.io.BufferedReader reader)
Read the content of the BufferedReader and return it as a String.
|
static java.lang.String |
getText(java.io.InputStream is)
Read the content of this InputStream and return it as a String.
|
static java.lang.String |
getText(java.io.InputStream is,
java.lang.String charset)
Read the content of this InputStream using specified charset and return
it as a String.
|
static java.lang.String |
getText(java.io.Reader reader)
Read the content of the Reader and return it as a String.
|
static java.util.Iterator<java.lang.Byte> |
iterator(java.io.DataInputStream self)
Standard iterator for a data input stream which iterates through the
stream content a Byte at a time.
|
static java.util.Iterator<java.lang.Byte> |
iterator(java.io.InputStream self)
Standard iterator for a input stream which iterates through the stream
content in a byte-based fashion.
|
static java.util.Iterator<java.lang.String> |
iterator(java.io.Reader self)
Creates an iterator which will traverse through the reader a line at a time.
|
static java.lang.Appendable |
leftShift(java.lang.Appendable self,
java.lang.Object value)
Overloads the leftShift operator for Appendable to allow an object to be appended
using Groovy's default representation for the object.
|
static void |
leftShift(java.io.ObjectOutputStream self,
java.lang.Object value)
Overloads the leftShift operator to add objects to an ObjectOutputStream.
|
static java.io.OutputStream |
leftShift(java.io.OutputStream self,
byte[] value)
Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.
|
static java.io.OutputStream |
leftShift(java.io.OutputStream self,
java.io.InputStream in)
Pipe an InputStream into an OutputStream for efficient stream copying.
|
static java.io.Writer |
leftShift(java.io.OutputStream self,
java.lang.Object value)
Overloads the leftShift operator to provide an append mechanism to add values to a stream.
|
static java.io.Writer |
leftShift(java.io.Writer self,
java.lang.Object value)
Overloads the leftShift operator for Writer to allow an object to be written
using Groovy's default representation for the object.
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.InputStream inputStream)
Create an object input stream for this input stream.
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.InputStream inputStream,
java.lang.ClassLoader classLoader)
Create an object input stream for this input stream using the given class loader.
|
static java.io.ObjectOutputStream |
newObjectOutputStream(java.io.OutputStream outputStream)
Create an object output stream for this output stream.
|
static java.io.PrintWriter |
newPrintWriter(java.io.Writer writer)
Create a new PrintWriter for this file, using specified
charset.
|
static java.io.BufferedReader |
newReader(java.io.InputStream self)
Creates a reader for this input stream.
|
static java.io.BufferedReader |
newReader(java.io.InputStream self,
java.lang.String charset)
Creates a reader for this input stream, using the specified
charset as the encoding.
|
static java.lang.String |
readLine(java.io.Reader self)
Read a single, whole line from the given Reader.
|
static java.util.List<java.lang.String> |
readLines(java.io.InputStream stream)
Reads the stream into a list, with one element for each line.
|
static java.util.List<java.lang.String> |
readLines(java.io.InputStream stream,
java.lang.String charset)
Reads the stream into a list, with one element for each line.
|
static java.util.List<java.lang.String> |
readLines(java.io.Reader reader)
Reads the reader into a list of Strings, with one entry for each line.
|
static void |
setBytes(java.io.OutputStream os,
byte[] bytes)
Write the byte[] to the output stream.
|
static <T> T |
splitEachLine(java.io.InputStream stream,
java.util.regex.Pattern pattern,
Closure<T> closure)
Iterates through the given InputStream line by line, splitting each line using
the given separator Pattern.
|
static <T> T |
splitEachLine(java.io.InputStream stream,
java.util.regex.Pattern pattern,
java.lang.String charset,
Closure<T> closure)
Iterates through the given InputStream line by line using the specified
encoding, splitting each line using the given separator Pattern.
|
static <T> T |
splitEachLine(java.io.InputStream stream,
java.lang.String regex,
Closure<T> closure)
Iterates through the given InputStream line by line, splitting each line using
the given separator.
|
static <T> T |
splitEachLine(java.io.InputStream stream,
java.lang.String regex,
java.lang.String charset,
Closure<T> closure)
Iterates through the given InputStream line by line using the specified
encoding, splitting each line using the given separator.
|
static <T> T |
splitEachLine(java.io.Reader self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Iterates through the given reader line by line, splitting each line using
the given regex separator Pattern.
|
static <T> T |
splitEachLine(java.io.Reader self,
java.lang.String regex,
Closure<T> closure)
Iterates through the given reader line by line, splitting each line using
the given regex separator.
|
static void |
transformChar(java.io.Reader self,
java.io.Writer writer,
Closure closure)
Transforms each character from this reader by passing it to the given
closure.
|
static void |
transformLine(java.io.Reader reader,
java.io.Writer writer,
Closure closure)
Transforms the lines from a reader with a Closure and
write them to a writer.
|
static java.lang.Appendable |
withFormatter(java.lang.Appendable self,
Closure closure)
Invokes a Closure that uses a Formatter taking care of resource handling.
|
static java.lang.Appendable |
withFormatter(java.lang.Appendable self,
java.util.Locale locale,
Closure closure)
Invokes a Closure that uses a Formatter taking care of resource handling.
|
static <T> T |
withObjectInputStream(java.io.InputStream inputStream,
java.lang.ClassLoader classLoader,
Closure<T> closure)
Create a new ObjectInputStream for this file and pass it to the closure.
|
static <T> T |
withObjectInputStream(java.io.InputStream inputStream,
Closure<T> closure)
Create a new ObjectInputStream for this file and pass it to the closure.
|
static <T> T |
withObjectOutputStream(java.io.OutputStream outputStream,
Closure<T> closure)
Create a new ObjectOutputStream for this output stream and then pass it to the
closure.
|
static <T> T |
withPrintWriter(java.io.Writer writer,
Closure<T> closure)
Create a new PrintWriter with a specified charset for
this file.
|
static <T> T |
withReader(java.io.InputStream in,
Closure<T> closure)
Helper method to create a new Reader for a stream and then
passes it into the closure.
|
static <T> T |
withReader(java.io.InputStream in,
java.lang.String charset,
Closure<T> closure)
Helper method to create a new Reader for a stream and then
passes it into the closure.
|
static <T> T |
withReader(java.io.Reader reader,
Closure<T> closure)
Allows this reader to be used within the closure, ensuring that it
is closed before this method returns.
|
static <T> T |
withStream(java.io.InputStream stream,
Closure<T> closure)
Allows this input stream to be used within the closure, ensuring that it
is flushed and closed before this method returns.
|
static <T> T |
withStream(java.io.OutputStream os,
Closure<T> closure)
Passes this OutputStream to the closure, ensuring that the stream
is closed after the closure returns, regardless of errors.
|
static <T> T |
withWriter(java.io.OutputStream stream,
Closure<T> closure)
Creates a writer from this stream, passing it to the given closure.
|
static <T> T |
withWriter(java.io.OutputStream stream,
java.lang.String charset,
Closure<T> closure)
Creates a writer from this stream, passing it to the given closure.
|
static <T> T |
withWriter(java.io.Writer writer,
Closure<T> closure)
Allows this writer to be used within the closure, ensuring that it
is flushed and closed before this method returns.
|
static void |
write(java.io.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(java.io.BufferedWriter writer,
java.lang.String line)
Write the text and append a newline (using the platform's line-ending).
|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders
public static java.io.Writer leftShift(java.io.Writer self, java.lang.Object value) throws java.io.IOException
self
- a Writervalue
- an Object whose default representation will be written to the Writerjava.io.IOException
- if an I/O error occurs.public static java.lang.Appendable leftShift(java.lang.Appendable self, java.lang.Object value) throws java.io.IOException
self
- an Appendablevalue
- an Object whose default representation will be appended to the Appendablejava.io.IOException
- if an I/O error occurs.public static java.lang.Appendable withFormatter(java.lang.Appendable self, Closure closure)
self
- an Appendableclosure
- a 1-arg Closure which will be called with a Formatter as its argumentpublic static java.lang.Appendable withFormatter(java.lang.Appendable self, java.util.Locale locale, Closure closure)
self
- an Appendablelocale
- a Locale used when creating the Formatterclosure
- a 1-arg Closure which will be called with a Formatter as its argumentpublic static void write(java.io.Writer self, Writable writable) throws java.io.IOException
self
- a Writerwritable
- an object implementing the Writable interfacejava.io.IOException
- if an I/O error occurs.public static java.io.Writer leftShift(java.io.OutputStream self, java.lang.Object value) throws java.io.IOException
self
- an OutputStreamvalue
- a value to appendjava.io.IOException
- if an I/O error occurs.public static void leftShift(java.io.ObjectOutputStream self, java.lang.Object value) throws java.io.IOException
self
- an ObjectOutputStreamvalue
- an object to write to the streamjava.io.IOException
- if an I/O error occurs.public static java.io.OutputStream leftShift(java.io.OutputStream self, java.io.InputStream in) throws java.io.IOException
self
- stream on which to writein
- stream to read fromjava.io.IOException
- if an I/O error occurs.public static java.io.OutputStream leftShift(java.io.OutputStream self, byte[] value) throws java.io.IOException
self
- an OutputStreamvalue
- a value to appendjava.io.IOException
- if an I/O error occurs.public static java.io.ObjectOutputStream newObjectOutputStream(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- an output streamjava.io.IOException
- if an IOException occurs.public static <T> T withObjectOutputStream(java.io.OutputStream outputStream, Closure<T> closure) throws java.io.IOException
outputStream
- am output streamclosure
- a closurejava.io.IOException
- if an IOException occurs.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.io.ObjectInputStream newObjectInputStream(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- an input streamjava.io.IOException
- if an IOException occurs.public static java.io.ObjectInputStream newObjectInputStream(java.io.InputStream inputStream, java.lang.ClassLoader classLoader) throws java.io.IOException
inputStream
- an input streamclassLoader
- the class loader to use when loading the classjava.io.IOException
- if an IOException occurs.public static void eachObject(java.io.ObjectInputStream ois, Closure closure) throws java.io.IOException, java.lang.ClassNotFoundException
ois
- an ObjectInputStream, closed after the operationclosure
- a closurejava.io.IOException
- if an IOException occurs.java.lang.ClassNotFoundException
- if the class is not found.public static <T> T withObjectInputStream(java.io.InputStream inputStream, Closure<T> closure) throws java.io.IOException
inputStream
- an input streamclosure
- a closurejava.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static <T> T withObjectInputStream(java.io.InputStream inputStream, java.lang.ClassLoader classLoader, Closure<T> closure) throws java.io.IOException
inputStream
- an input streamclassLoader
- the class loader to use when loading the classclosure
- a closurejava.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static <T> T eachLine(java.io.InputStream stream, java.lang.String charset, Closure<T> closure) throws java.io.IOException
stream
- a streamcharset
- opens the stream with a specified charsetclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)java.io.IOException
- if an IOException occurs.eachLine(java.io.InputStream, java.lang.String, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.InputStream stream, java.lang.String charset, int firstLine, Closure<T> closure) throws java.io.IOException
stream
- a streamcharset
- opens the stream with a specified charsetfirstLine
- 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)java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.InputStream stream, Closure<T> closure) throws java.io.IOException
stream
- a streamclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)java.io.IOException
- if an IOException occurs.eachLine(java.io.InputStream, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.InputStream stream, int firstLine, Closure<T> closure) throws java.io.IOException
stream
- a streamfirstLine
- 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)java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.Reader self, Closure<T> closure) throws java.io.IOException
self
- a Reader, closed after the method returnsclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.Reader self, int firstLine, Closure<T> closure) throws java.io.IOException
self
- a Reader, closed after the method returnsfirstLine
- 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)java.io.IOException
- if an IOException occurs.public static <T> T splitEachLine(java.io.Reader self, java.lang.String regex, Closure<T> closure) throws java.io.IOException
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|'
self
- a Reader, closed after the method returnsregex
- the delimiting regular expressionclosure
- a closurejava.io.IOException
- if an IOException occurs.java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.split(java.lang.String)
public static <T> T splitEachLine(java.io.Reader self, java.util.regex.Pattern pattern, Closure<T> closure) throws java.io.IOException
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|'
self
- a Reader, closed after the method returnspattern
- the regular expression Pattern for the delimiterclosure
- a closurejava.io.IOException
- if an IOException occurs.java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.split(java.lang.String)
public static <T> T splitEachLine(java.io.InputStream stream, java.lang.String regex, java.lang.String charset, Closure<T> closure) throws java.io.IOException
stream
- an InputStreamregex
- the delimiting regular expressioncharset
- opens the stream with a specified charsetclosure
- a closurejava.io.IOException
- if an IOException occurs.java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.InputStream stream, java.util.regex.Pattern pattern, java.lang.String charset, Closure<T> closure) throws java.io.IOException
stream
- an InputStreampattern
- the regular expression Pattern for the delimitercharset
- opens the stream with a specified charsetclosure
- a closurejava.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.InputStream stream, java.lang.String regex, Closure<T> closure) throws java.io.IOException
stream
- an InputStreamregex
- the delimiting regular expressionclosure
- a closurejava.io.IOException
- if an IOException occurs.java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.InputStream stream, java.util.regex.Pattern pattern, Closure<T> closure) throws java.io.IOException
stream
- an InputStreampattern
- the regular expression Pattern for the delimiterclosure
- a closurejava.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.String readLine(java.io.Reader self) throws java.io.IOException
self
- a Readerjava.io.IOException
- if an IOException occurs.public static java.util.List<java.lang.String> readLines(java.io.InputStream stream) throws java.io.IOException
stream
- a streamjava.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.InputStream stream, java.lang.String charset) throws java.io.IOException
stream
- a streamcharset
- opens the stream with a specified charsetjava.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.Reader reader) throws java.io.IOException
reader
- a Readerjava.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.InputStream is) throws java.io.IOException
is
- an input streamjava.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.InputStream is, java.lang.String charset) throws java.io.IOException
is
- an input streamcharset
- opens the stream with a specified charsetjava.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.Reader reader) throws java.io.IOException
reader
- a Reader whose content we want to readjava.io.IOException
- if an IOException occurs.getText(java.io.BufferedReader)
public static java.lang.String getText(java.io.BufferedReader reader) throws java.io.IOException
reader
- a BufferedReader whose content we want to readjava.io.IOException
- if an IOException occurs.public static byte[] getBytes(java.io.InputStream is) throws java.io.IOException
is
- an input streamjava.io.IOException
- if an IOException occurs.public static void setBytes(java.io.OutputStream os, byte[] bytes) throws java.io.IOException
os
- an output streambytes
- the byte[] to write to the output streamjava.io.IOException
- if an IOException occurs.public static void writeLine(java.io.BufferedWriter writer, java.lang.String line) throws java.io.IOException
writer
- a BufferedWriterline
- the line to writejava.io.IOException
- if an IOException occurs.public static java.util.Iterator<java.lang.String> iterator(java.io.Reader self)
self
- a Reader objectBufferedReader.readLine()
public static java.util.Iterator<java.lang.Byte> iterator(java.io.InputStream self)
self
- an InputStream objectpublic static java.util.Iterator<java.lang.Byte> iterator(java.io.DataInputStream self)
self
- a DataInputStream objectpublic static java.io.BufferedReader newReader(java.io.InputStream self)
self
- an input streampublic static java.io.BufferedReader newReader(java.io.InputStream self, java.lang.String charset) throws java.io.UnsupportedEncodingException
self
- an input streamcharset
- the charset for this input streamjava.io.UnsupportedEncodingException
- if the encoding specified is not supportedpublic static java.io.PrintWriter newPrintWriter(java.io.Writer writer)
writer
- a writerpublic static <T> T withPrintWriter(java.io.Writer writer, Closure<T> closure) throws java.io.IOException
writer
- a writerclosure
- the closure to invoke with the PrintWriterjava.io.IOException
- if an IOException occurs.public static <T> T withWriter(java.io.Writer writer, Closure<T> closure) throws java.io.IOException
writer
- the writer which is used and then closedclosure
- the closure that the writer is passed intojava.io.IOException
- if an IOException occurs.public static <T> T withReader(java.io.Reader reader, Closure<T> closure) throws java.io.IOException
reader
- the reader which is used and then closedclosure
- the closure that the writer is passed intojava.io.IOException
- if an IOException occurs.public static <T> T withStream(java.io.InputStream stream, Closure<T> closure) throws java.io.IOException
stream
- the stream which is used and then closedclosure
- the closure that the stream is passed intojava.io.IOException
- if an IOException occurs.public static <T> T withReader(java.io.InputStream in, Closure<T> closure) throws java.io.IOException
in
- a streamclosure
- the closure to invoke with the InputStreamjava.io.IOException
- if an IOException occurs.InputStreamReader
public static <T> T withReader(java.io.InputStream in, java.lang.String charset, Closure<T> closure) throws java.io.IOException
in
- a streamcharset
- the charset used to decode the streamclosure
- the closure to invoke with the readerjava.io.IOException
- if an IOException occurs.InputStreamReader
public static <T> T withWriter(java.io.OutputStream stream, Closure<T> closure) throws java.io.IOException
stream
- the stream which is used and then closedclosure
- the closure that the writer is passed intojava.io.IOException
- if an IOException occurs.withWriter(java.io.Writer, groovy.lang.Closure)
public static <T> T withWriter(java.io.OutputStream stream, java.lang.String charset, Closure<T> closure) throws java.io.IOException
stream
- the stream which is used and then closedcharset
- the charset usedclosure
- the closure that the writer is passed intojava.io.IOException
- if an IOException occurs.withWriter(java.io.Writer, groovy.lang.Closure)
public static <T> T withStream(java.io.OutputStream os, Closure<T> closure) throws java.io.IOException
os
- the stream which is used and then closedclosure
- the closure that the stream is passed intojava.io.IOException
- if an IOException occurs.public static void eachByte(java.io.InputStream is, Closure closure) throws java.io.IOException
is
- stream to iterate over, closed after the method callclosure
- closure to apply to each bytejava.io.IOException
- if an IOException occurs.public static void eachByte(java.io.InputStream is, int bufferLen, Closure closure) throws java.io.IOException
is
- stream to iterate over, closed after the method call.bufferLen
- the length of the buffer to use.closure
- a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.java.io.IOException
- if an IOException occurs.public static void transformChar(java.io.Reader self, java.io.Writer writer, Closure closure) throws java.io.IOException
self
- a Reader objectwriter
- a Writer to receive the transformed charactersclosure
- a closure that performs the required transformationjava.io.IOException
- if an IOException occurs.public static void transformLine(java.io.Reader reader, java.io.Writer writer, Closure closure) throws java.io.IOException
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.java.io.IOException
- if an IOException occurs.public static void filterLine(java.io.Reader reader, java.io.Writer writer, Closure closure) throws java.io.IOException
reader
- a reader, closed after the callwriter
- a writer, closed after the callclosure
- the closure which returns booleansjava.io.IOException
- if an IOException occurs.public static Writable filterLine(java.io.Reader reader, Closure closure)
true
if the line should be passed to the writer.reader
- this readerclosure
- a closure used for filteringpublic static Writable filterLine(java.io.InputStream self, Closure predicate)
true
if the line should be passed to the writer.self
- an input streampredicate
- a closure which returns boolean and takes a linefilterLine(java.io.Reader, groovy.lang.Closure)
public static Writable filterLine(java.io.InputStream self, java.lang.String charset, Closure predicate) throws java.io.UnsupportedEncodingException
true
if the line should be passed to the writer.self
- an input streamcharset
- opens the stream with a specified charsetpredicate
- a closure which returns boolean and takes a linejava.io.UnsupportedEncodingException
- if the encoding specified is not supportedfilterLine(java.io.Reader, groovy.lang.Closure)
public static void filterLine(java.io.InputStream self, java.io.Writer writer, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.self
- the InputStreamwriter
- a writer to write output topredicate
- a closure which returns true if a line should be acceptedjava.io.IOException
- if an IOException occurs.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static void filterLine(java.io.InputStream self, java.io.Writer writer, java.lang.String charset, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.self
- the InputStreamwriter
- a writer to write output tocharset
- opens the stream with a specified charsetpredicate
- a closure which returns true if a line should be acceptedjava.io.IOException
- if an IOException occurs.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)