|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.runtime.ResourceGroovyMethods
public class ResourceGroovyMethods
This class defines new groovy methods for Readers, Writers, InputStreams and
OutputStreams 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 T eachLine(InputStream self, Closure c)
provides a eachLine(Closure c)
method for InputStream
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport |
---|
DefaultGroovyMethodsSupport.RangeInfo |
Constructor Summary | |
---|---|
ResourceGroovyMethods()
|
Method Summary | ||
---|---|---|
static void |
append(java.io.File file,
byte[] bytes)
Append bytes to the end of a File. |
|
static void |
append(java.io.File self,
java.io.InputStream stream)
Append binary data to the file. |
|
static void |
append(java.io.File file,
java.lang.Object text)
Append the text at the end of the File. |
|
static void |
append(java.io.File file,
java.lang.Object text,
java.lang.String charset)
Append the text at the end of the File, using a specified encoding. |
|
static
|
asType(java.io.File f,
java.lang.Class<T> c)
Converts this File to a Writable or delegates to default
DefaultGroovyMethods.asType(java.lang.Object, java.lang.Class) . |
|
static java.io.File |
asWritable(java.io.File file)
Converts this File to a Writable . |
|
static java.io.File |
asWritable(java.io.File file,
java.lang.String encoding)
Allows a file to return a Writable implementation that can output itself to a Writer stream. |
|
static boolean |
deleteDir(java.io.File self)
Deletes a directory with all contained files and subdirectories. |
|
static void |
eachByte(java.io.File self,
Closure closure)
Traverse through each byte of this File |
|
static void |
eachByte(java.io.File self,
int bufferLen,
Closure closure)
Traverse through the bytes of this File, bufferLen bytes at a time. |
|
static void |
eachByte(java.net.URL url,
Closure closure)
Reads the InputStream from this URL, passing each byte to the given closure. |
|
static void |
eachByte(java.net.URL url,
int bufferLen,
Closure closure)
Reads the InputStream from this URL, passing a byte[] and a number of bytes to the given closure. |
|
static void |
eachDir(java.io.File self,
Closure closure)
Invokes the closure for each subdirectory in this directory, ignoring regular files. |
|
static void |
eachDirMatch(java.io.File self,
java.lang.Object nameFilter,
Closure closure)
Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
static void |
eachDirRecurse(java.io.File self,
Closure closure)
Invokes the closure for each descendant directory of this directory. |
|
static void |
eachFile(java.io.File self,
Closure closure)
Invokes the closure for each 'child' file in this 'parent' folder/directory. |
|
static void |
eachFile(java.io.File self,
FileType fileType,
Closure closure)
Invokes the closure for each 'child' file in this 'parent' folder/directory. |
|
static void |
eachFileMatch(java.io.File self,
FileType fileType,
java.lang.Object nameFilter,
Closure closure)
Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
static void |
eachFileMatch(java.io.File self,
java.lang.Object nameFilter,
Closure closure)
Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
static void |
eachFileRecurse(java.io.File self,
Closure closure)
Invokes the closure for each descendant file in this directory. |
|
static void |
eachFileRecurse(java.io.File self,
FileType fileType,
Closure closure)
Invokes the closure for each descendant file in this directory. |
|
static
|
eachLine(java.io.File self,
Closure<T> closure)
Iterates through this file line by line. |
|
static
|
eachLine(java.io.File self,
int firstLine,
Closure<T> closure)
Iterates through this file line by line. |
|
static
|
eachLine(java.io.File self,
java.lang.String charset,
Closure<T> closure)
Iterates through this file line by line. |
|
static
|
eachLine(java.io.File self,
java.lang.String charset,
int firstLine,
Closure<T> closure)
Iterates through this file line by line. |
|
static
|
eachLine(java.net.URL url,
Closure<T> closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static
|
eachLine(java.net.URL url,
int firstLine,
Closure<T> closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static
|
eachLine(java.net.URL url,
java.lang.String charset,
Closure<T> closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static
|
eachLine(java.net.URL url,
java.lang.String charset,
int firstLine,
Closure<T> closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static void |
eachObject(java.io.File self,
Closure closure)
Iterates through the given file object by object. |
|
static Writable |
filterLine(java.io.File self,
Closure closure)
Filters the lines of a File and creates a Writable in return to stream the filtered lines. |
|
static Writable |
filterLine(java.io.File self,
java.lang.String charset,
Closure closure)
Filters the lines of a File and creates a Writable in return to stream the filtered lines. |
|
static void |
filterLine(java.io.File self,
java.io.Writer writer,
Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
|
static void |
filterLine(java.io.File self,
java.io.Writer writer,
java.lang.String charset,
Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
|
static Writable |
filterLine(java.net.URL self,
Closure predicate)
Filter lines from a URL using a closure predicate. |
|
static Writable |
filterLine(java.net.URL self,
java.lang.String charset,
Closure predicate)
Filter lines from a URL using a closure predicate. |
|
static void |
filterLine(java.net.URL self,
java.io.Writer writer,
Closure predicate)
Uses a closure to filter lines from this URL and pass them to the given writer. |
|
static void |
filterLine(java.net.URL self,
java.io.Writer writer,
java.lang.String charset,
Closure predicate)
Uses a closure to filter lines from this URL and pass them to the given writer. |
|
static byte[] |
getBytes(java.io.File file)
Read the content of the File and returns it as a byte[]. |
|
static byte[] |
getBytes(java.net.URL url)
Read the content of this URL and returns it as a byte[]. |
|
static java.lang.String |
getText(java.io.File file)
Read the content of the File and returns it as a String. |
|
static java.lang.String |
getText(java.io.File file,
java.lang.String charset)
Read the content of the File using the specified encoding and return it as a String. |
|
static java.lang.String |
getText(java.net.URL url)
Read the content of this URL and returns it as a String. |
|
static java.lang.String |
getText(java.net.URL url,
java.util.Map parameters)
Read the content of this URL and returns it as a String. |
|
static java.lang.String |
getText(java.net.URL url,
java.util.Map parameters,
java.lang.String charset)
Read the data from this URL and return it as a String. |
|
static java.lang.String |
getText(java.net.URL url,
java.lang.String charset)
Read the data from this URL and return it as a String. |
|
static java.io.File |
leftShift(java.io.File file,
byte[] bytes)
Write bytes to a File. |
|
static java.io.File |
leftShift(java.io.File file,
java.io.InputStream data)
Append binary data to the file. |
|
static java.io.File |
leftShift(java.io.File file,
java.lang.Object text)
Write the text to the File. |
|
static java.io.DataInputStream |
newDataInputStream(java.io.File file)
Create a data input stream for this file |
|
static java.io.DataOutputStream |
newDataOutputStream(java.io.File file)
Creates a new data output stream for this file. |
|
static java.io.BufferedInputStream |
newInputStream(java.io.File file)
Creates a buffered input stream for this file. |
|
static java.io.BufferedInputStream |
newInputStream(java.net.URL url)
Creates a buffered input stream for this URL. |
|
static java.io.BufferedInputStream |
newInputStream(java.net.URL url,
java.util.Map parameters)
Creates a buffered input stream for this URL. |
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.File file)
Create an object input stream for this file. |
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.File file,
java.lang.ClassLoader classLoader)
Create an object input stream for this file using the given class loader. |
|
static java.io.ObjectOutputStream |
newObjectOutputStream(java.io.File file)
Create an object output stream for this file. |
|
static java.io.BufferedOutputStream |
newOutputStream(java.io.File file)
Create a buffered output stream for this file. |
|
static java.io.PrintWriter |
newPrintWriter(java.io.File file)
Create a new PrintWriter for this file. |
|
static java.io.PrintWriter |
newPrintWriter(java.io.File file,
java.lang.String charset)
Create a new PrintWriter for this file, using specified charset. |
|
static java.io.BufferedReader |
newReader(java.io.File file)
Create a buffered reader for this file. |
|
static java.io.BufferedReader |
newReader(java.io.File file,
java.lang.String charset)
Create a buffered reader for this file, using the specified charset as the encoding. |
|
static java.io.BufferedReader |
newReader(java.net.URL url)
Creates a buffered reader for this URL. |
|
static java.io.BufferedReader |
newReader(java.net.URL url,
java.util.Map parameters)
Creates a buffered reader for this URL. |
|
static java.io.BufferedReader |
newReader(java.net.URL url,
java.util.Map parameters,
java.lang.String charset)
Creates a buffered reader for this URL using the given encoding. |
|
static java.io.BufferedReader |
newReader(java.net.URL url,
java.lang.String charset)
Creates a buffered reader for this URL using the given encoding. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file)
Create a buffered writer for this file. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file,
boolean append)
Creates a buffered writer for this file, optionally appending to the existing file content. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file,
java.lang.String charset)
Creates a buffered writer for this file, writing data using the given encoding. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file,
java.lang.String charset,
boolean append)
Helper method to create a buffered writer for a file. |
|
static byte[] |
readBytes(java.io.File file)
Reads the content of the file into a byte array. |
|
static java.util.List<java.lang.String> |
readLines(java.io.File file)
Reads the file into a list of Strings, with one item for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.io.File file,
java.lang.String charset)
Reads the file into a list of Strings, with one item for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.net.URL self)
Reads the URL contents into a list, with one element for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.net.URL self,
java.lang.String charset)
Reads the URL contents into a list, with one element for each line. |
|
static boolean |
renameTo(java.io.File self,
java.lang.String newPathName)
Renames the file. |
|
static void |
setBytes(java.io.File file,
byte[] bytes)
Write the bytes from the byte array to the File. |
|
static void |
setText(java.io.File file,
java.lang.String text)
Synonym for write(text) allowing file.text = 'foo'. |
|
static void |
setText(java.io.File file,
java.lang.String text,
java.lang.String charset)
Synonym for write(text, charset) allowing: myFile.setText('some text', charset) or with some help from ExpandoMetaClass , you could do something like:
myFile.metaClass.setText = { String s -> delegate.setText(s, 'UTF-8') }
myfile.text = 'some text'
|
|
static long |
size(java.io.File self)
Provide the standard Groovy size() method for File . |
|
static
|
splitEachLine(java.io.File self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Iterates through this file line by line, splitting each line using the given separator Pattern. |
|
static
|
splitEachLine(java.io.File self,
java.util.regex.Pattern pattern,
java.lang.String charset,
Closure<T> closure)
Iterates through this file line by line, splitting each line using the given regex separator Pattern. |
|
static
|
splitEachLine(java.io.File self,
java.lang.String regex,
Closure<T> closure)
Iterates through this file line by line, splitting each line using the given regex separator. |
|
static
|
splitEachLine(java.io.File self,
java.lang.String regex,
java.lang.String charset,
Closure<T> closure)
Iterates through this file line by line, splitting each line using the given regex separator. |
|
static
|
splitEachLine(java.net.URL self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. |
|
static
|
splitEachLine(java.net.URL self,
java.util.regex.Pattern pattern,
java.lang.String charset,
Closure<T> closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. |
|
static
|
splitEachLine(java.net.URL self,
java.lang.String regex,
Closure<T> closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. |
|
static
|
splitEachLine(java.net.URL self,
java.lang.String regex,
java.lang.String charset,
Closure<T> closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. |
|
static java.net.URI |
toURI(java.lang.CharSequence self)
Transforms a CharSequence representing a URI into a URI object. |
|
static java.net.URI |
toURI(java.lang.String self)
Transforms a String representing a URI into a URI object. |
|
static java.net.URL |
toURL(java.lang.CharSequence self)
Transforms a CharSequence representing a URL into a URL object. |
|
static java.net.URL |
toURL(java.lang.String self)
Transforms a String representing a URL into a URL object. |
|
static void |
traverse(java.io.File self,
Closure closure)
Invokes the closure for each descendant file in this directory tree. |
|
static void |
traverse(java.io.File self,
java.util.Map<java.lang.String,java.lang.Object> options)
Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. |
|
static void |
traverse(java.io.File self,
java.util.Map<java.lang.String,java.lang.Object> options,
Closure closure)
Invokes closure for each descendant file in this directory tree. |
|
static
|
withDataInputStream(java.io.File file,
Closure<T> closure)
Create a new DataInputStream for this file and passes it into the closure. |
|
static
|
withDataOutputStream(java.io.File file,
Closure<T> closure)
Create a new DataOutputStream for this file and passes it into the closure. |
|
static java.lang.Object |
withInputStream(java.io.File file,
Closure closure)
Create a new InputStream for this file and passes it into the closure. |
|
static
|
withInputStream(java.net.URL url,
Closure<T> closure)
Creates a new InputStream for this URL and passes it into the closure. |
|
static
|
withObjectInputStream(java.io.File file,
java.lang.ClassLoader classLoader,
Closure<T> closure)
Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure. |
|
static
|
withObjectInputStream(java.io.File file,
Closure<T> closure)
Create a new ObjectInputStream for this file and pass it to the closure. |
|
static
|
withObjectOutputStream(java.io.File file,
Closure<T> closure)
Create a new ObjectOutputStream for this file and then pass it to the closure. |
|
static java.lang.Object |
withOutputStream(java.io.File file,
Closure closure)
Creates a new OutputStream for this file and passes it into the closure. |
|
static
|
withPrintWriter(java.io.File file,
Closure<T> closure)
Create a new PrintWriter for this file which is then passed it into the given closure. |
|
static
|
withPrintWriter(java.io.File file,
java.lang.String charset,
Closure<T> closure)
Create a new PrintWriter with a specified charset for this file. |
|
static
|
withReader(java.io.File file,
Closure<T> closure)
Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns. |
|
static
|
withReader(java.io.File file,
java.lang.String charset,
Closure<T> closure)
Create a new BufferedReader for this file using the specified charset and then passes it into the closure, ensuring the reader is closed after the closure returns. |
|
static
|
withReader(java.net.URL url,
Closure<T> closure)
Helper method to create a new BufferedReader for a URL and then passes it to the closure. |
|
static
|
withReader(java.net.URL url,
java.lang.String charset,
Closure<T> closure)
Helper method to create a new Reader for a URL and then passes it to the closure. |
|
static
|
withWriter(java.io.File file,
Closure<T> closure)
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
|
static
|
withWriter(java.io.File file,
java.lang.String charset,
Closure<T> closure)
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
|
static
|
withWriterAppend(java.io.File file,
Closure<T> closure)
Create a new BufferedWriter for this file in append mode. |
|
static
|
withWriterAppend(java.io.File file,
java.lang.String charset,
Closure<T> closure)
Create a new BufferedWriter which will append to this file. |
|
static void |
write(java.io.File file,
java.lang.String text)
Write the text to the File. |
|
static void |
write(java.io.File file,
java.lang.String text,
java.lang.String charset)
Write the text to the File, using the specified encoding. |
Methods inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport |
---|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResourceGroovyMethods()
Method Detail |
---|
public static long size(java.io.File self)
size()
method for File
.
self
- a file object
public static java.io.ObjectOutputStream newObjectOutputStream(java.io.File file) throws java.io.IOException
file
- a file
java.io.IOException
- if an IOException occurs.public static <T> T withObjectOutputStream(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.io.ObjectInputStream newObjectInputStream(java.io.File file) throws java.io.IOException
file
- a file
java.io.IOException
- if an IOException occurs.public static java.io.ObjectInputStream newObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader) throws java.io.IOException
file
- a fileclassLoader
- the class loader to use when loading the class
java.io.IOException
- if an IOException occurs.public static void eachObject(java.io.File self, Closure closure) throws java.io.IOException, java.lang.ClassNotFoundException
self
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.lang.ClassNotFoundException
- if the class is not found.IOGroovyMethods.eachObject(java.io.ObjectInputStream, groovy.lang.Closure)
public static <T> T withObjectInputStream(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.InputStream, groovy.lang.Closure)
public static <T> T withObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader, Closure<T> closure) throws java.io.IOException
file
- a FileclassLoader
- the class loader to use when loading the classclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.InputStream, groovy.lang.Closure)
public static <T> T eachLine(java.io.File self, Closure<T> closure) throws java.io.IOException
self
- a Fileclosure
- 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.File, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.File self, java.lang.String charset, Closure<T> closure) throws java.io.IOException
self
- a Filecharset
- opens the file 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.File, java.lang.String, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.File self, int firstLine, Closure<T> closure) throws java.io.IOException
self
- a FilefirstLine
- 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.IOGroovyMethods.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static <T> T eachLine(java.io.File self, java.lang.String charset, int firstLine, Closure<T> closure) throws java.io.IOException
self
- a Filecharset
- opens the file 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.IOGroovyMethods.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static <T> T eachLine(java.net.URL url, Closure<T> closure) throws java.io.IOException
url
- a URL to open and readclosure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.net.URL, int, groovy.lang.Closure)
public static <T> T eachLine(java.net.URL url, int firstLine, Closure<T> closure) throws java.io.IOException
url
- a URL to open and readfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.IOGroovyMethods.eachLine(java.io.InputStream, int, groovy.lang.Closure)
public static <T> T eachLine(java.net.URL url, java.lang.String charset, Closure<T> closure) throws java.io.IOException
url
- a URL to open and readcharset
- opens the stream with a specified charsetclosure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.net.URL, java.lang.String, int, groovy.lang.Closure)
public static <T> T eachLine(java.net.URL url, java.lang.String charset, int firstLine, Closure<T> closure) throws java.io.IOException
url
- a URL to open and readcharset
- 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 to apply on each line (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.IOGroovyMethods.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.File self, java.lang.String regex, Closure<T> closure) throws java.io.IOException
self
- a Fileregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidIOGroovyMethods.splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.File self, java.util.regex.Pattern pattern, Closure<T> closure) throws java.io.IOException
self
- a Filepattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.File self, java.lang.String regex, java.lang.String charset, Closure<T> closure) throws java.io.IOException
self
- a Fileregex
- the delimiting regular expressioncharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidIOGroovyMethods.splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static <T> T splitEachLine(java.io.File self, java.util.regex.Pattern pattern, java.lang.String charset, Closure<T> closure) throws java.io.IOException
self
- a Filepattern
- the regular expression Pattern for the delimitercharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static <T> T splitEachLine(java.net.URL self, java.lang.String regex, Closure<T> closure) throws java.io.IOException
self
- a URL to open and readregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidIOGroovyMethods.splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static <T> T splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, Closure<T> closure) throws java.io.IOException
self
- a URL to open and readpattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static <T> T splitEachLine(java.net.URL self, java.lang.String regex, java.lang.String charset, Closure<T> closure) throws java.io.IOException
self
- a URL to open and readregex
- the delimiting regular expressioncharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidIOGroovyMethods.splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static <T> T splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, java.lang.String charset, Closure<T> closure) throws java.io.IOException
self
- a URL to open and readpattern
- the regular expression Pattern for the delimitercharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.util.List<java.lang.String> readLines(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.IOGroovyMethods.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- a Filecharset
- opens the file with a specified charset
java.io.IOException
- if an IOException occurs.IOGroovyMethods.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.net.URL self) throws java.io.IOException
self
- a URL
java.io.IOException
- if an IOException occurs.IOGroovyMethods.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.net.URL self, java.lang.String charset) throws java.io.IOException
self
- a URLcharset
- opens the URL with a specified charset
java.io.IOException
- if an IOException occurs.IOGroovyMethods.readLines(java.io.Reader)
public static java.lang.String getText(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- the file whose content we want to readcharset
- the charset used to read the content of the file
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.File file) throws java.io.IOException
file
- the file whose content we want to read
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.net.URL url) throws java.io.IOException
url
- URL to read content from
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.net.URL url, java.util.Map parameters) throws java.io.IOException
url
- URL to read content fromparameters
- connection parameters
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.net.URL url, java.lang.String charset) throws java.io.IOException
url
- URL to read content fromcharset
- opens the stream with a specified charset
java.io.IOException
- if an IOException occurs.URLConnection.getInputStream()
public static java.lang.String getText(java.net.URL url, java.util.Map parameters, java.lang.String charset) throws java.io.IOException
url
- URL to read content fromparameters
- connection parameterscharset
- opens the stream with a specified charset
java.io.IOException
- if an IOException occurs.URLConnection.getInputStream()
public static byte[] getBytes(java.io.File file) throws java.io.IOException
file
- the file whose content we want to read
java.io.IOException
- if an IOException occurs.public static byte[] getBytes(java.net.URL url) throws java.io.IOException
url
- URL to read content from
java.io.IOException
- if an IOException occurs.public static void setBytes(java.io.File file, byte[] bytes) throws java.io.IOException
file
- the file to write tobytes
- the byte[] to write to the file
java.io.IOException
- if an IOException occurs.public static void write(java.io.File file, java.lang.String text) throws java.io.IOException
file
- a Filetext
- the text to write to the File
java.io.IOException
- if an IOException occurs.public static void setText(java.io.File file, java.lang.String text) throws java.io.IOException
file
- a Filetext
- the text to write to the File
java.io.IOException
- if an IOException occurs.write(java.io.File, java.lang.String)
public static void setText(java.io.File file, java.lang.String text, java.lang.String charset) throws java.io.IOException
myFile.setText('some text', charset)or with some help from
ExpandoMetaClass
, you could do something like:
myFile.metaClass.setText = { String s -> delegate.setText(s, 'UTF-8') } myfile.text = 'some text'
file
- A Filecharset
- The charset used when writing to the filetext
- The text to write to the File
java.io.IOException
- if an IOException occurs.write(java.io.File, java.lang.String, java.lang.String)
public static java.io.File leftShift(java.io.File file, java.lang.Object text) throws java.io.IOException
file
- a Filetext
- the text to write to the File
java.io.IOException
- if an IOException occurs.public static java.io.File leftShift(java.io.File file, byte[] bytes) throws java.io.IOException
file
- a Filebytes
- the byte array to append to the end of the File
java.io.IOException
- if an IOException occurs.public static java.io.File leftShift(java.io.File file, java.io.InputStream data) throws java.io.IOException
append(java.io.File, java.io.InputStream)
file
- a Filedata
- an InputStream of data to write to the file
java.io.IOException
- if an IOException occurs.public static void write(java.io.File file, java.lang.String text, java.lang.String charset) throws java.io.IOException
file
- a Filetext
- the text to write to the Filecharset
- the charset used
java.io.IOException
- if an IOException occurs.public static void append(java.io.File file, java.lang.Object text) throws java.io.IOException
file
- a Filetext
- the text to append at the end of the File
java.io.IOException
- if an IOException occurs.public static void append(java.io.File file, byte[] bytes) throws java.io.IOException
file
- a Filebytes
- the byte array to append to the end of the File
java.io.IOException
- if an IOException occurs.public static void append(java.io.File self, java.io.InputStream stream) throws java.io.IOException
self
- a Filestream
- stream to read data from.
java.io.IOException
- if an IOException occurs.public static void append(java.io.File file, java.lang.Object text, java.lang.String charset) throws java.io.IOException
file
- a Filetext
- the text to append at the end of the Filecharset
- the charset used
java.io.IOException
- if an IOException occurs.public static void eachFile(java.io.File self, FileType fileType, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a file objectfileType
- if normal files or directories or both should be processedclosure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorypublic static void eachFile(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a File (that happens to be a folder/directory)closure
- a closure (first parameter is the 'child' file)
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryFile.listFiles()
,
eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachDir(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a File (that happens to be a folder/directory)closure
- a closure (first parameter is the subdirectory file)
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryFile.listFiles()
,
eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachFileRecurse(java.io.File self, FileType fileType, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a file objectfileType
- if normal files or directories or both should be processedclosure
- the closure to invoke on each file
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorypublic static void traverse(java.io.File self, java.util.Map<java.lang.String,java.lang.Object> options, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
closure
for each descendant file in this directory tree.
Sub-directories are recursively traversed as found.
The traversal can be adapted by providing various options in the options
Map according
to the following keys:FileType
enum to determine if normal files or directories or both are processedClosure
run before each directory is processed and optionally returning a FileVisitResult
value
which can be used to control subsequent processing.Closure
run after each directory is processed and optionally returning a FileVisitResult
value
which can be used to control subsequent processing.FileType.FILES
)DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method). If set,
only files/dirs which match are candidates for visiting.DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method). If set,
only files/dirs which match are candidates for visiting. (Must not be set if 'filter' is set)DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method).
If set, any candidates which match won't be visited.DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method).
If set, any candidates which match won't be visited. (Must not be set if 'excludeFilter' is set)Closure
which if set causes the files and subdirectories for each directory to be processed in sorted order.
Note that even when processing only files, the order of visited subdirectories will be affected by this parameter.def totalSize = 0 def count = 0 def sortByTypeThenName = { a, b -> a.isFile() != b.isFile() ? a.isFile() <=> b.isFile() : a.name <=> b.name } rootDir.traverse( type : FILES, nameFilter : ~/.*\.groovy/, preDir : { if (it.name == '.svn') return SKIP_SUBTREE }, postDir : { println "Found $count files in $it.name totalling $totalSize bytes" totalSize = 0; count = 0 }, postRoot : true sort : sortByTypeThenName ) {it -> totalSize += it.size(); count++ }
self
- a Fileoptions
- a Map of options to alter the traversal behaviorclosure
- the Closure to invoke on each file/directory and optionally returning a FileVisitResult
value
which can be used to control subsequent processing
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directory or illegal filter combinations are suppliedDefaultGroovyMethods.sort(java.util.Collection, groovy.lang.Closure)
,
FileVisitResult
,
FileType
public static void traverse(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
traverse(java.io.File, java.util.Map, groovy.lang.Closure)
when
no options to alter the traversal behavior are required.
self
- a Fileclosure
- the Closure to invoke on each file/directory and optionally returning a FileVisitResult
value
which can be used to control subsequent processing
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorytraverse(java.io.File, java.util.Map, groovy.lang.Closure)
public static void traverse(java.io.File self, java.util.Map<java.lang.String,java.lang.Object> options) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
traverse(java.io.File, java.util.Map, groovy.lang.Closure)
allowing the 'visit' closure
to be included in the options Map rather than as a parameter.
self
- a Fileoptions
- a Map of options to alter the traversal behavior
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directory or illegal filter combinations are suppliedtraverse(java.io.File, java.util.Map, groovy.lang.Closure)
public static void eachFileRecurse(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a Fileclosure
- a closure
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachDirRecurse(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a directoryclosure
- a closure
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachFileMatch(java.io.File self, FileType fileType, java.lang.Object nameFilter, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method to determine if a match occurs. This method can be used
with different kinds of filters like regular expressions, classes, ranges etc.
Both regular files and subdirectories may be candidates for matching depending
on the value of fileType.
// collect names of files in baseDir matching supplied regex pattern import static groovy.io.FileType.* def names = [] baseDir.eachFileMatch FILES, ~/foo\d\.txt/, { names << it.name } assert names == ['foo1.txt', 'foo2.txt'] // remove all *.bak files in baseDir baseDir.eachFileMatch FILES, ~/.*\.bak/, { File bak -> bak.delete() } // print out files > 4K in size from baseDir baseDir.eachFileMatch FILES, { new File(baseDir, it).size() > 4096 }, { println "$it.name ${it.size()}" }
self
- a filefileType
- whether normal files or directories or both should be processednameFilter
- the filter to perform on the name of the file/directory (using the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method)closure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorypublic static void eachFileMatch(java.io.File self, java.lang.Object nameFilter, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method to determine if a match occurs. This method can be used
with different kinds of filters like regular expressions, classes, ranges etc.
Both regular files and subdirectories are matched.
self
- a filenameFilter
- the nameFilter to perform on the name of the file (using the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method)closure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
public static void eachDirMatch(java.io.File self, java.lang.Object nameFilter, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method to determine if a match occurs. This method can be used
with different kinds of filters like regular expressions, classes, ranges etc.
Only subdirectories are matched; regular files are ignored.
self
- a filenameFilter
- the nameFilter to perform on the name of the directory (using the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object)
method)closure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
public static boolean deleteDir(java.io.File self)
The method returns
self
- a File
public static boolean renameTo(java.io.File self, java.lang.String newPathName)
File.renameTo(File)
self
- a FilenewPathName
- The new pathname for the named file
true
if and only if the renaming succeeded;
false
otherwisepublic static java.io.File asWritable(java.io.File file)
Writable
.
file
- a File
public static <T> T asType(java.io.File f, java.lang.Class<T> c)
Writable
or delegates to default
DefaultGroovyMethods.asType(java.lang.Object, java.lang.Class)
.
f
- a Filec
- the desired class
public static java.io.File asWritable(java.io.File file, java.lang.String encoding)
file
- a Fileencoding
- the encoding to be used when reading the file's contents
public static java.io.BufferedReader newReader(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.io.BufferedReader newReader(java.io.File file, java.lang.String charset) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException
file
- a Filecharset
- the charset for this File
java.io.FileNotFoundException
- if the File was not found
java.io.UnsupportedEncodingException
- if the encoding specified is not supportedpublic static <T> T withReader(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a file objectclosure
- a closure
java.io.IOException
- if an IOException occurs.public static <T> T withReader(java.io.File file, java.lang.String charset, Closure<T> closure) throws java.io.IOException
file
- a file objectcharset
- the charset for this input streamclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.io.BufferedOutputStream newOutputStream(java.io.File file) throws java.io.IOException
file
- a file object
java.io.IOException
- if an IOException occurs.public static java.io.DataOutputStream newDataOutputStream(java.io.File file) throws java.io.IOException
file
- a file object
java.io.IOException
- if an IOException occurs.public static java.lang.Object withOutputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.lang.Object withInputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.InputStream, groovy.lang.Closure)
public static <T> T withInputStream(java.net.URL url, Closure<T> closure) throws java.io.IOException
url
- a URLclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.InputStream, groovy.lang.Closure)
public static <T> T withDataOutputStream(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.OutputStream, groovy.lang.Closure)
public static <T> T withDataInputStream(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.io.BufferedWriter newWriter(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.io.BufferedWriter newWriter(java.io.File file, boolean append) throws java.io.IOException
file
- a Fileappend
- true if data should be appended to the file
java.io.IOException
- if an IOException occurs.public static java.io.BufferedWriter newWriter(java.io.File file, java.lang.String charset, boolean append) throws java.io.IOException
file
- a Filecharset
- the name of the encoding used to write in this fileappend
- true if in append mode
java.io.IOException
- if an IOException occurs.public static java.io.BufferedWriter newWriter(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- a Filecharset
- the name of the encoding used to write in this file
java.io.IOException
- if an IOException occurs.public static <T> T withWriter(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.public static <T> T withWriter(java.io.File file, java.lang.String charset, Closure<T> closure) throws java.io.IOException
file
- a Filecharset
- the charset usedclosure
- a closure
java.io.IOException
- if an IOException occurs.public static <T> T withWriterAppend(java.io.File file, java.lang.String charset, Closure<T> closure) throws java.io.IOException
file
- a Filecharset
- the charset usedclosure
- a closure
java.io.IOException
- if an IOException occurs.public static <T> T withWriterAppend(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.io.PrintWriter newPrintWriter(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.io.PrintWriter newPrintWriter(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- a Filecharset
- the charset
java.io.IOException
- if an IOException occurs.public static <T> T withPrintWriter(java.io.File file, Closure<T> closure) throws java.io.IOException
file
- a Fileclosure
- the closure to invoke with the PrintWriter
java.io.IOException
- if an IOException occurs.public static <T> T withPrintWriter(java.io.File file, java.lang.String charset, Closure<T> closure) throws java.io.IOException
file
- a Filecharset
- the charsetclosure
- the closure to invoke with the PrintWriter
java.io.IOException
- if an IOException occurs.public static <T> T withReader(java.net.URL url, Closure<T> closure) throws java.io.IOException
url
- a URLclosure
- the closure to invoke with the reader
java.io.IOException
- if an IOException occurs.public static <T> T withReader(java.net.URL url, java.lang.String charset, Closure<T> closure) throws java.io.IOException
url
- a URLcharset
- the charset usedclosure
- the closure to invoke with the reader
java.io.IOException
- if an IOException occurs.public static java.io.BufferedInputStream newInputStream(java.io.File file) throws java.io.FileNotFoundException
file
- a File
java.io.FileNotFoundException
- if the file is not found.public static java.io.BufferedInputStream newInputStream(java.net.URL url) throws java.net.MalformedURLException, java.io.IOException
url
- a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedInputStream newInputStream(java.net.URL url, java.util.Map parameters) throws java.net.MalformedURLException, java.io.IOException
url
- a URLparameters
- connection parameters
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedReader newReader(java.net.URL url) throws java.net.MalformedURLException, java.io.IOException
url
- a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedReader newReader(java.net.URL url, java.util.Map parameters) throws java.net.MalformedURLException, java.io.IOException
url
- a URLparameters
- connection parameters
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedReader newReader(java.net.URL url, java.lang.String charset) throws java.net.MalformedURLException, java.io.IOException
url
- a URLcharset
- opens the stream with a specified charset
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedReader newReader(java.net.URL url, java.util.Map parameters, java.lang.String charset) throws java.net.MalformedURLException, java.io.IOException
url
- a URLparameters
- connection parameterscharset
- opens the stream with a specified charset
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.DataInputStream newDataInputStream(java.io.File file) throws java.io.FileNotFoundException
file
- a File
java.io.FileNotFoundException
- if the file is not found.public static void eachByte(java.io.File self, Closure closure) throws java.io.IOException
self
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.IOGroovyMethods.eachByte(java.io.InputStream, groovy.lang.Closure)
public static void eachByte(java.io.File self, int bufferLen, Closure closure) throws java.io.IOException
self
- a FilebufferLen
- 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.IOGroovyMethods.eachByte(java.io.InputStream, int, groovy.lang.Closure)
public static void eachByte(java.net.URL url, Closure closure) throws java.io.IOException
url
- url to iterate overclosure
- closure to apply to each byte
java.io.IOException
- if an IOException occurs.IOGroovyMethods.eachByte(java.io.InputStream, groovy.lang.Closure)
public static void eachByte(java.net.URL url, int bufferLen, Closure closure) throws java.io.IOException
url
- url to iterate overbufferLen
- 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.IOGroovyMethods.eachByte(java.io.InputStream, int, groovy.lang.Closure)
public static Writable filterLine(java.io.File self, Closure closure) throws java.io.IOException
self
- a Fileclosure
- a closure which returns a boolean indicating to filter
the line or not
java.io.IOException
- if self
is not readableIOGroovyMethods.filterLine(java.io.Reader, groovy.lang.Closure)
public static Writable filterLine(java.io.File self, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Filecharset
- opens the file with a specified charsetclosure
- a closure which returns a boolean indicating to filter
the line or not
java.io.IOException
- if an IOException occursIOGroovyMethods.filterLine(java.io.Reader, groovy.lang.Closure)
public static void filterLine(java.io.File self, java.io.Writer writer, Closure closure) throws java.io.IOException
self
- a Filewriter
- a writer destination to write filtered lines toclosure
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer.
java.io.IOException
- if self
is not readableIOGroovyMethods.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static void filterLine(java.io.File self, java.io.Writer writer, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Filewriter
- a writer destination to write filtered lines tocharset
- opens the file with a specified charsetclosure
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer.
java.io.IOException
- if an IO error occursIOGroovyMethods.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static Writable filterLine(java.net.URL self, Closure predicate) throws java.io.IOException
true
if the line should be passed to the writer.
self
- a URLpredicate
- a closure which returns boolean and takes a line
java.io.IOException
- if an IO exception occursIOGroovyMethods.filterLine(java.io.Reader, groovy.lang.Closure)
public static Writable filterLine(java.net.URL self, java.lang.String charset, Closure predicate) throws java.io.IOException
true
if the line should be passed to the writer.
self
- the URLcharset
- opens the URL with a specified charsetpredicate
- a closure which returns boolean and takes a line
java.io.IOException
- if an IO exception occursIOGroovyMethods.filterLine(java.io.Reader, groovy.lang.Closure)
public static void filterLine(java.net.URL self, java.io.Writer writer, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.
self
- the URLwriter
- a writer to write output topredicate
- a closure which returns true if a line should be accepted
java.io.IOException
- if an IOException occurs.IOGroovyMethods.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static void filterLine(java.net.URL 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 URLwriter
- a writer to write output tocharset
- opens the URL with a specified charsetpredicate
- a closure which returns true if a line should be accepted
java.io.IOException
- if an IOException occurs.IOGroovyMethods.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static byte[] readBytes(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.net.URI toURI(java.lang.CharSequence self) throws java.net.URISyntaxException
self
- the CharSequence representing a URI
java.net.URISyntaxException
- is thrown if the URI is not well formed.public static java.net.URI toURI(java.lang.String self) throws java.net.URISyntaxException
self
- the String representing a URI
java.net.URISyntaxException
- is thrown if the URI is not well formed.public static java.net.URL toURL(java.lang.CharSequence self) throws java.net.MalformedURLException
self
- the CharSequence representing a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed.public static java.net.URL toURL(java.lang.String self) throws java.net.MalformedURLException
self
- the String representing a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |