Groovy JDK

java.io
Class InputStream

Method Summary
void eachByte(Closure)
Traverse through each byte of the specified stream.
Object eachLine(String, Closure)
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure.
Object eachLine(String, int, Closure)
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure.
Object eachLine(Closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure.
Object eachLine(int, Closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure.
Writable filterLine(Closure)
Filter lines from an input stream using a closure predicate.
Writable filterLine(String, Closure)
Filter lines from an input stream using a closure predicate.
void filterLine(Writer, Closure)
Uses a closure to filter lines from this InputStream and pass them to the given writer.
void filterLine(Writer, String, Closure)
Uses a closure to filter lines from this InputStream and pass them to the given writer.
byte[] getBytes()
Read the content of this InputStream and return it as a byte[].
String getText()
Read the content of this InputStream and return it as a String.
String getText(String)
Read the content of this InputStream using specified charset and return it as a String.
Iterator iterator()
Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.
ObjectInputStream newObjectInputStream()
Create an object input stream for this input stream.
ObjectInputStream newObjectInputStream(ClassLoader)
Create an object input stream for this input stream using the given class loader.
BufferedReader newReader()
Creates a reader for this input stream.
BufferedReader newReader(String)
Creates a reader for this input stream, using the specified charset as the encoding.
String readLine()
Just throws a DeprecationException.
List readLines()
Reads the stream into a list, with one element for each line.
List readLines(String)
Reads the stream into a list, with one element for each line.
Object splitEachLine(String, String, Closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator.
Object splitEachLine(Pattern, String, Closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern.
Object splitEachLine(String, Closure)
Iterates through the given InputStream line by line, splitting each line using the given separator.
Object splitEachLine(Pattern, Closure)
Iterates through the given InputStream line by line, splitting each line using the given separator Pattern.
Object withObjectInputStream(Closure)
Create a new ObjectInputStream for this file and pass it to the closure.
Object withObjectInputStream(ClassLoader, Closure)
Create a new ObjectInputStream for this file and pass it to the closure.
Object withReader(Closure)
Helper method to create a new Reader for a stream and then passes it into the closure.
Object withReader(String, Closure)
Helper method to create a new Reader for a stream and then passes it into the closure.
Object withStream(Closure)
Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns.
 
Method Detail

eachByte

public void eachByte(Closure)
 
Traverse through each byte of the specified stream. The stream is closed after the closure returns.
Parameters:
closure - closure to apply to each byte.
Since:
1.0

eachLine

public Object eachLine(String, 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.
Parameters:
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
Since:
1.5.5
See:
InputStream#eachLine.

eachLine

public Object eachLine(String, int, 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.
Parameters:
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
Since:
1.5.7
See:
Reader#eachLine.

eachLine

public Object eachLine(Closure)
 
Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
Parameters:
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
Since:
1.5.6
See:
InputStream#eachLine.

eachLine

public Object eachLine(int, Closure)
 
Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
Parameters:
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
Since:
1.5.7
See:
Reader#eachLine.

filterLine

public Writable filterLine(Closure)
 
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:
predicate - a closure which returns boolean and takes a line.
Returns:
a writable which writes out the filtered lines
Since:
1.0
See:
Reader#filterLine.

filterLine

public Writable filterLine(String, Closure)
 
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:
charset - opens the stream with a specified charset.
predicate - a closure which returns boolean and takes a line.
Returns:
a writable which writes out the filtered lines
Since:
1.6.8
See:
Reader#filterLine.

filterLine

public void filterLine(Writer, Closure)
 
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.
Parameters:
writer - a writer to write output to.
predicate - a closure which returns true if a line should be accepted.
Since:
1.0
See:
Reader#filterLine.

filterLine

public void filterLine(Writer, String, Closure)
 
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.
Parameters:
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.
Since:
1.6.8
See:
Reader#filterLine.

getBytes

public byte[] getBytes()
 
Read the content of this InputStream and return it as a byte[]. The stream is closed before this method returns.
Returns:
the byte[] from that InputStream
Since:
1.7.1

getText

public String getText()
 
Read the content of this InputStream and return it as a String. The stream is closed before this method returns.
Returns:
the text from that URL
Since:
1.0

getText

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

iterator

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

newObjectInputStream

public ObjectInputStream newObjectInputStream()
 
Create an object input stream for this input stream.
Returns:
an object input stream
Since:
1.5.0

newObjectInputStream

public ObjectInputStream newObjectInputStream(ClassLoader)
 
Create an object input stream for this input stream using the given class loader.
Parameters:
classLoader - the class loader to use when loading the class.
Returns:
an object input stream
Since:
1.5.0

newReader

public BufferedReader newReader()
 
Creates a reader for this input stream.
Returns:
a reader
Since:
1.0

newReader

public BufferedReader newReader(String)
 
Creates a reader for this input stream, using the specified charset as the encoding.
Parameters:
charset - the charset for this input stream.
Returns:
a reader
Since:
1.6.0

readLine

public String readLine()
 
Just throws a DeprecationException. DO NOT USE. It used to read a single, whole line from the given InputStream.
Returns:
a line
Since:
1.0

readLines

public List readLines()
 
Reads the stream into a list, with one element for each line.
Returns:
a List of lines
Since:
1.0
See:
Reader#readLines.

readLines

public List readLines(String)
 
Reads the stream into a list, with one element for each line.
Parameters:
charset - opens the stream with a specified charset.
Returns:
a List of lines
Since:
1.6.8
See:
Reader#readLines.

splitEachLine

public Object splitEachLine(String, String, 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.
Parameters:
regex - the delimiting regular expression.
charset - opens the stream with a specified charset.
closure - a closure.
Returns:
the last value returned by the closure
Since:
1.5.5
See:
Reader#splitEachLine.

splitEachLine

public Object splitEachLine(Pattern, String, 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.
Parameters:
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
Since:
1.6.8
See:
Reader#splitEachLine.

splitEachLine

public Object splitEachLine(String, 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.
Parameters:
regex - the delimiting regular expression.
closure - a closure.
Returns:
the last value returned by the closure
Since:
1.5.6
See:
Reader#splitEachLine.

splitEachLine

public Object splitEachLine(Pattern, 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.
Parameters:
pattern - the regular expression Pattern for the delimiter.
closure - a closure.
Returns:
the last value returned by the closure
Since:
1.6.8
See:
Reader#splitEachLine.

withObjectInputStream

public Object withObjectInputStream(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.
Parameters:
closure - a closure.
Returns:
the value returned by the closure
Since:
1.5.0
See:
InputStream#withStream.

withObjectInputStream

public Object withObjectInputStream(ClassLoader, 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.
Parameters:
classLoader - the class loader to use when loading the class.
closure - a closure.
Returns:
the value returned by the closure
Since:
1.5.0
See:
InputStream#withStream.

withReader

public Object withReader(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.
Parameters:
closure - the closure to invoke with the InputStream.
Returns:
the value returned by the closure
Since:
1.5.2
See:
InputStreamReader.

withReader

public Object withReader(String, 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.
Parameters:
charset - the charset used to decode the stream.
closure - the closure to invoke with the reader.
Returns:
the value returned by the closure
Since:
1.5.6
See:
InputStreamReader.

withStream

public Object withStream(Closure)
 
Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns.
Parameters:
closure - the closure that the stream is passed into.
Returns:
the value returned by the closure
Since:
1.5.2

Groovy JDK