Top Description Constructors Methods
org.codehaus.groovy.runtime

public Class ResourceGroovyMethods

extends DefaultGroovyMethodsSupport
Class Inheritance
Imports
groovy.io.EncodingAwareBufferedWriter, .FileType, .FileVisitResult, .GroovyPrintWriter, groovy.lang.Closure, .MetaClass, .Writable, groovy.transform.NamedParam, groovy.transform.stc.ClosureParams, .FromString, .PickFirstResolver, .SimpleType, groovy.util.CharsetToolkit, org.codehaus.groovy.runtime.callsite.BooleanReturningMethodInvoker, org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation, java.io.BufferedInputStream, .BufferedOutputStream, .BufferedReader, .BufferedWriter, .DataInputStream, .DataOutputStream, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .FileWriter, .IOException, .InputStream, .InputStreamReader, .ObjectInputStream, .ObjectOutputStream, .OutputStream, .OutputStreamWriter, .PrintWriter, .Reader, .UnsupportedEncodingException, .Writer, java.net.MalformedURLException, .URI, .URISyntaxException, .URL, .URLConnection, java.nio.charset.Charset, java.util.ArrayList, .Arrays, .HashMap, .Iterator, .List, .Map, java.util.regex.Pattern

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.

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.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
append(File
a File
file
,
Object
the text to append at the end of the File
text
)

Append the text at the end of the File without writing a BOM.

public static void
append(File
a File
file
,
Object
the text to append at the end of the File
text
,
boolean
whether to write a BOM
writeBom
)

Append the text at the end of the File.

public static void
append(File
a File
file
,
Reader
the Reader supplying the text to append at the end of the File
reader
)

Append the text supplied by the Writer at the end of the File without writing a BOM.

public static void
append(File
a File
file
,
Writer
the Writer supplying the text to append at the end of the File
writer
)

Append the text supplied by the Writer at the end of the File without writing a BOM.

public static void
append(File
a File
file
,
Writer
the Writer supplying the text to append at the end of the File
writer
,
boolean
whether to write a BOM
writeBom
)

Append the text supplied by the Writer at the end of the File.

public static void
append(File
a File
file
,
byte[]
the byte array to append to the end of the File
bytes
)

Append bytes to the end of a File.

public static void
append(File
a File
self
,
InputStream
stream to read data from.
stream
)

Append binary data to the file.

public static void
append(File
a File
file
,
Object
the text to append at the end of the File
text
,
String
the charset used
charset
)

Append the text at the end of the File without writing a BOM, using a specified encoding.

public static void
append(File
a File
file
,
Object
the text to append at the end of the File
text
,
String
the charset used
charset
,
boolean
whether to write a BOM
writeBom
)

Append the text at the end of the File, using a specified encoding.

public static void
append(File
a File
file
,
Writer
the Writer supplying the text to append at the end of the File
writer
,
String
the charset used
charset
)

Append the text supplied by the Writer at the end of the File without writing a BOM, using a specified encoding.

public static void
append(File
a File
file
,
Writer
the Writer supplying the text to append at the end of the File
writer
,
String
the charset used
charset
,
boolean
whether to write a BOM
writeBom
)

Append the text supplied by the Writer at the end of the File, using a specified encoding.

public static void
append(File
a File
file
,
Reader
the Reader supplying the text to append at the end of the File
reader
,
boolean
whether to write a BOM
writeBom
)

Append the text supplied by the Reader at the end of the File, using a specified encoding.

public static void
append(File
a File
file
,
Reader
the Reader supplying the text to append at the end of the File
reader
,
String
the charset used
charset
)

Append the text supplied by the Reader at the end of the File without writing a BOM, using a specified encoding.

public static void
append(File
a File
file
,
Reader
the Reader supplying the text to append at the end of the File
reader
,
String
the charset used
charset
,
boolean
whether to write a BOM
writeBom
)

Append the text supplied by the Reader at the end of the File, using a specified encoding.

private static void
appendBuffered(File file, Object text, boolean writeBom)

private static void
appendBuffered(File file, Object text, String charset, boolean writeBom)

public static <T> T

Returns:

the converted object
asType
(File
a File
f
,
Class<T>
the desired class
c
)

Converts this File to a groovy.lang.Writable or delegates to default DefaultGroovyMethods#asType(java.lang.Object, java.lang.Class).

public static File

Returns:

a File which wraps the input file and which implements Writable
asWritable
(File
a File
file
)

Converts this File to a groovy.lang.Writable.

public static File

Returns:

File which wraps the input file and which implements Writable
asWritable
(File
a File
file
,
String
the encoding to be used when reading the file's contents
encoding
)

Allows a file to return a Writable implementation that can output itself to a Writer stream.

private static void
checkDir(File
The directory to check
dir
)

This method is used to throw useful exceptions when the eachFile* and eachDir closure methods are used incorrectly.

private static InputStream

Returns:

an InputStream from the underlying URLConnection
configuredInputStream
(Map<K, V>
an optional map specifying part or all of supported connection parameters
parameters
,
URL
the url for which to create the inputstream
url
)

Creates an inputstream for this URL, with the possibility to set different connection parameters using the parameters map:

  • connectTimeout : the connection timeout
  • readTimeout : the read timeout
  • useCaches : set the use cache property for the URL connection
  • allowUserInteraction : set the user interaction flag for the URL connection
  • requestProperties : a map of properties to be passed to the URL connection
public static boolean

Returns:

true if the file doesn't exist or deletion was successful
deleteDir
(final File
a File
self
)

Deletes a directory with all contained files and subdirectories.

public static long

Returns:

directory size (length)
directorySize
(File
a file object
self
)

Calculates directory size as total size of all its files, recursively.

public static void
eachByte(File
a File
self
,
Closure<V>
a closure
closure
)

Traverse through each byte of this File

public static void
eachByte(File
a File
self
,
int
the length of the buffer to use.
bufferLen
,
Closure<V>
a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
closure
)

Traverse through the bytes of this File, bufferLen bytes at a time.

public static void
eachByte(URL
url to iterate over
url
,
Closure<V>
closure to apply to each byte
closure
)

Reads the InputStream from this URL, passing each byte to the given closure.

public static void
eachByte(URL
url to iterate over
url
,
int
the length of the buffer to use.
bufferLen
,
Closure<V>
a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
closure
)

Reads the InputStream from this URL, passing a byte[] and a number of bytes to the given closure.

public static void
eachDir(File
a File (that happens to be a folder/directory)
self
,
Closure<V>
a closure (the parameter passed is the subdirectory file)
closure
)

Invokes the closure for each subdirectory in this directory, ignoring regular files.

public static void
eachDirMatch(final File
a File (that happens to be a folder/directory)
self
,
final Object
the nameFilter to perform on the name of the directory (using the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method)
nameFilter
,
final Closure<V>
the closure to invoke
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.

public static void
eachDirRecurse(final File
a File (that happens to be a folder/directory)
self
,
final Closure<V>
a closure
closure
)

Recursively processes each descendant subdirectory in this directory.

public static void
eachFile(final File
a File (that happens to be a folder/directory)
self
,
final FileType
if normal files or directories or both should be processed
fileType
,
final Closure<V>
the closure to invoke
closure
)

Invokes the closure for each 'child' file in this 'parent' folder/directory.

public static void
eachFile(final File
a File (that happens to be a folder/directory)
self
,
final Closure<V>
a closure (the parameter passed is the 'child' file)
closure
)

Invokes the closure for each 'child' file in this 'parent' folder/directory.

public static void
eachFileMatch(final File
a File (that happens to be a folder/directory)
self
,
final FileType
whether normal files or directories or both should be processed
fileType
,
final Object
the filter to perform on the name of the file/directory (using the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method)
nameFilter
,
final Closure<V>
the closure to invoke
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.

public static void
eachFileMatch(final File
a File (that happens to be a folder/directory)
self
,
final Object
the nameFilter to perform on the name of the file (using the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method)
nameFilter
,
final Closure<V>
the closure to invoke
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.

public static void
eachFileRecurse(final File
a File (that happens to be a folder/directory)
self
,
final FileType
if normal files or directories or both should be processed
fileType
,
final Closure<V>
the closure to invoke on each file
closure
)

Processes each descendant file in this directory and any sub-directories.

public static void
eachFileRecurse(File
a File (that happens to be a folder/directory)
self
,
Closure<V>
a Closure
closure
)

Processes each descendant file in this directory and any sub-directories.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(File
a File
self
,
Closure<T>
a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
closure
)

Iterates through this file line by line.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(File
a File
self
,
String
opens the file with a specified charset
charset
,
Closure<T>
a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
closure
)

Iterates through this file line by line.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(File
a File
self
,
int
the line number value used for the first line (default is 1, set to 0 to start counting from 0)
firstLine
,
Closure<T>
a closure (arg 1 is line, optional arg 2 is line number)
closure
)

Iterates through this file line by line.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(File
a File
self
,
String
opens the file with a specified charset
charset
,
int
the line number value used for the first line (default is 1, set to 0 to start counting from 0)
firstLine
,
Closure<T>
a closure (arg 1 is line, optional arg 2 is line number)
closure
)

Iterates through this file line by line.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(URL
a URL to open and read
url
,
Closure<T>
a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
closure
)

Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(URL
a URL to open and read
url
,
int
the line number value used for the first line (default is 1, set to 0 to start counting from 0)
firstLine
,
Closure<T>
a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
closure
)

Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(URL
a URL to open and read
url
,
String
opens the stream with a specified charset
charset
,
Closure<T>
a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
closure
)

Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(URL
a URL to open and read
url
,
String
opens the stream with a specified charset
charset
,
int
the line number value used for the first line (default is 1, set to 0 to start counting from 0)
firstLine
,
Closure<T>
a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
closure
)

Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.

public static void
eachObject(File
a File
self
,
Closure<V>
a closure
closure
)

Iterates through the given file object by object.

public static Writable

Returns:

a Writable closure
filterLine
(File
a File
self
,
Closure<V>
a closure which returns a boolean indicating to filter the line or not
closure
)

Filters the lines of a File and creates a Writable in return to stream the filtered lines.

public static Writable

Returns:

a Writable closure
filterLine
(File
a File
self
,
String
opens the file with a specified charset
charset
,
Closure<V>
a closure which returns a boolean indicating to filter the line or not
closure
)

Filters the lines of a File and creates a Writable in return to stream the filtered lines.

public static void
filterLine(File
a File
self
,
Writer
a writer destination to write filtered lines to
writer
,
Closure<V>
a closure which takes each line as a parameter and returns true if the line should be written to this writer.
closure
)

Filter the lines from this File, and write them to the given writer based on the given closure predicate.

public static void
filterLine(File
a File
self
,
Writer
a writer destination to write filtered lines to
writer
,
String
opens the file with a specified charset
charset
,
Closure<V>
a closure which takes each line as a parameter and returns true if the line should be written to this writer.
closure
)

Filter the lines from this File, and write them to the given writer based on the given closure predicate.

public static Writable

Returns:

a writable which writes out the filtered lines
filterLine
(URL
a URL
self
,
Closure<V>
a closure which returns boolean and takes a line
predicate
)

Filter lines from a URL using a closure predicate.

public static Writable

Returns:

a writable which writes out the filtered lines
filterLine
(URL
the URL
self
,
String
opens the URL with a specified charset
charset
,
Closure<V>
a closure which returns boolean and takes a line
predicate
)

Filter lines from a URL using a closure predicate.

public static void
filterLine(URL
the URL
self
,
Writer
a writer to write output to
writer
,
Closure<V>
a closure which returns true if a line should be accepted
predicate
)

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

public static void
filterLine(URL
the URL
self
,
Writer
a writer to write output to
writer
,
String
opens the URL with a specified charset
charset
,
Closure<V>
a closure which returns true if a line should be accepted
predicate
)

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

public static byte[]

Returns:

a String containing the content of the file
getBytes
(File
the file whose content we want to read
file
)

Read the content of the File and returns it as a byte[].

public static byte[]

Returns:

the byte[] from that URL
getBytes
(URL
URL to read content from
url
)

Read the content of this URL and returns it as a byte[].

public static byte[]

Returns:

the byte[] from that URL
getBytes
(URL
URL to read content from
url
,
Map<K, V>
connection parameters
parameters
)

Read the content of this URL and returns it as a byte[].

private static String

Returns:

String, never null
getPath
(List<E>
List of Strings to be concatenated as a path.
pathStack
)

Gets path from a List of Strings.

private static String

Returns:

String, never null
getPath
(final List<E>
List of Strings to be concated as a path.
pathStack
,
final char
char to be used as separator between names in path
separatorChar
)

Gets path from a List of Strings.

private static String[]

Returns:

Strings, never null
getPathStack
(String
to get names from
path
)

Gets all names of the path as an array of Strings.

public static String

Returns:

a String containing the content of the file
getText
(File
the file whose content we want to read
file
,
String
the charset used to read the content of the file
charset
)

Read the content of the File using the specified encoding and return it as a String.

public static String

Returns:

a String containing the content of the file
getText
(File
the file whose content we want to read
file
)

Read the content of the File and returns it as a String.

public static String

Returns:

the text from that URL
getText
(URL
URL to read content from
url
)

Read the content of this URL and returns it as a String.

public static String

Returns:

the text from that URL
getText
(URL
URL to read content from
url
,
Map<K, V>
connection parameters
parameters
)

Read the content of this URL and returns it as a String.

public static String

Returns:

the text from that URL
getText
(URL
URL to read content from
url
,
String
opens the stream with a specified charset
charset
)

Read the data from this URL and return it as a String.

public static String

Returns:

the text from that URL
getText
(URL
URL to read content from
url
,
Map<K, V>
connection parameters
parameters
,
String
opens the stream with a specified charset
charset
)

Read the data from this URL and return it as a String.

public static File

Returns:

the original file
leftShift
(File
a File
file
,
Object
the text to write to the File
text
)

Write the text to the File.

public static File

Returns:

the original file
leftShift
(File
a File
file
,
byte[]
the byte array to append to the end of the File
bytes
)

Write bytes to a File.

public static File

Returns:

the file
leftShift
(File
a File
file
,
InputStream
an InputStream of data to write to the file
data
)

Append binary data to the file.

public static DataInputStream

Returns:

a DataInputStream of the file
newDataInputStream
(File
a File
file
)

Create a data input stream for this file

public static DataOutputStream

Returns:

the created DataOutputStream
newDataOutputStream
(File
a file object
file
)

Creates a new data output stream for this file.

public static BufferedInputStream

Returns:

a BufferedInputStream of the file
newInputStream
(File
a File
file
)

Creates a buffered input stream for this file.

public static BufferedInputStream

Returns:

a BufferedInputStream for the URL
newInputStream
(URL
a URL
url
)

Creates a buffered input stream for this URL.

public static BufferedInputStream

Returns:

a BufferedInputStream for the URL
newInputStream
(URL
a URL
url
,
Map<K, V>
connection parameters
parameters
)

Creates a buffered input stream for this URL.

public static ObjectInputStream

Returns:

an object input stream
newObjectInputStream
(File
a file
file
)

Create an object input stream for this file.

public static ObjectInputStream

Returns:

an object input stream
newObjectInputStream
(File
a file
file
,
final ClassLoader
the class loader to use when loading the class
classLoader
)

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

public static ObjectOutputStream

Returns:

an object output stream
newObjectOutputStream
(File
a file
file
)

Create an object output stream for this file.

public static BufferedOutputStream

Returns:

the created OutputStream
newOutputStream
(File
a file object
file
)

Create a buffered output stream for this file.

public static PrintWriter

Returns:

the created PrintWriter
newPrintWriter
(File
a File
file
)

Create a new PrintWriter for this file.

public static PrintWriter

Returns:

a PrintWriter
newPrintWriter
(File
a File
file
,
String
the charset
charset
)

Create a new PrintWriter for this file, using specified charset.

public static BufferedReader

Returns:

a BufferedReader
newReader
(File
a File
file
)

Create a buffered reader for this file.

public static BufferedReader

Returns:

a BufferedReader
newReader
(File
a File
file
,
String
the charset for this File
charset
)

Create a buffered reader for this file, using the specified charset as the encoding.

public static BufferedReader

Returns:

a BufferedReader for the URL
newReader
(URL
a URL
url
)

Creates a buffered reader for this URL.

public static BufferedReader

Returns:

a BufferedReader for the URL
newReader
(URL
a URL
url
,
Map<K, V>
connection parameters
parameters
)

Creates a buffered reader for this URL.

public static BufferedReader

Returns:

a BufferedReader for the URL
newReader
(URL
a URL
url
,
String
opens the stream with a specified charset
charset
)

Creates a buffered reader for this URL using the given encoding.

public static BufferedReader

Returns:

a BufferedReader for the URL
newReader
(URL
a URL
url
,
Map<K, V>
connection parameters
parameters
,
String
opens the stream with a specified charset
charset
)

Creates a buffered reader for this URL using the given encoding.

public static BufferedWriter

Returns:

a BufferedWriter
newWriter
(File
a File
file
)

Create a buffered writer for this file.

public static BufferedWriter

Returns:

a BufferedWriter
newWriter
(File
a File
file
,
boolean
true if data should be appended to the file
append
)

Creates a buffered writer for this file, optionally appending to the existing file content.

public static BufferedWriter

Returns:

a BufferedWriter
newWriter
(File
a File
file
,
String
the name of the encoding used to write in this file
charset
,
boolean
true if in append mode
append
)

Helper method to create a buffered writer for a file without writing a BOM.

public static BufferedWriter

Returns:

a BufferedWriter
newWriter
(File
a File
file
,
String
the name of the encoding used to write in this file
charset
,
boolean
true if in append mode
append
,
boolean
whether to write a BOM
writeBom
)

Helper method to create a buffered writer for a file.

public static BufferedWriter

Returns:

a BufferedWriter
newWriter
(File
a File
file
,
String
the name of the encoding used to write in this file
charset
)

Creates a buffered writer for this file, writing data without writing a BOM, using a specified encoding.

private static boolean
notFiltered(File file, Object filter, Object nameFilter, Object excludeFilter, Object excludeNameFilter)

public static byte[]

Returns:

a byte array with the contents of the file.
readBytes
(File
a File
file
)

Reads the content of the file into a byte array.

public static List<String>

Returns:

a List of lines
readLines
(File
a File
file
)

Reads the file into a list of Strings, with one item for each line.

public static List<String>

Returns:

a List of lines
readLines
(File
a File
file
,
String
opens the file with a specified charset
charset
)

Reads the file into a list of Strings, with one item for each line.

public static List<String>

Returns:

a List of lines
readLines
(URL
a URL
self
)

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

public static List<String>

Returns:

a List of lines
readLines
(URL
a URL
self
,
String
opens the URL with a specified charset
charset
)

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

public static String

Returns:

the relative path between the files
relativePath
(File
the File to calculate the path from
self
,
File
the File to calculate the path to
to
)

Relative path to file.

public static boolean

Returns:

true if and only if the renaming succeeded; false otherwise
renameTo
(final File
a File
self
,
String
The new pathname for the named file
newPathName
)

Renames the file.

public static void
setBytes(File
the file to write to
file
,
byte[]
the byte[] to write to the file
bytes
)

Write the bytes from the byte array to the File.

public static void
setText(File
a File
file
,
String
the text to write to the File
text
)

Synonym for write(text) allowing file.text = 'foo'.

public static void
setText(File
A File
file
,
String
The text to write to the File
text
,
String
The charset used when writing to the file
charset
)

Synonym for write(text, charset) allowing:

myFile.setText('some text', charset)
public static long

Returns:

the file's size (length)
size
(File
a file object
self
)

Provide the standard Groovy size() method for File.

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(File
a File
self
,
String
the delimiting regular expression
regex
,
Closure<T>
a closure
closure
)

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

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(File
a File
self
,
Pattern
the regular expression Pattern for the delimiter
pattern
,
Closure<T>
a closure
closure
)

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

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(File
a File
self
,
String
the delimiting regular expression
regex
,
String
opens the file with a specified charset
charset
,
Closure<T>
a closure
closure
)

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

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(File
a File
self
,
Pattern
the regular expression Pattern for the delimiter
pattern
,
String
opens the file with a specified charset
charset
,
Closure<T>
a closure
closure
)

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

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(URL
a URL to open and read
self
,
String
the delimiting regular expression
regex
,
Closure<T>
a closure
closure
)

Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator.

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(URL
a URL to open and read
self
,
Pattern
the regular expression Pattern for the delimiter
pattern
,
Closure<T>
a closure
closure
)

Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern.

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(URL
a URL to open and read
self
,
String
the delimiting regular expression
regex
,
String
opens the file with a specified charset
charset
,
Closure<T>
a closure
closure
)

Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator.

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(URL
a URL to open and read
self
,
Pattern
the regular expression Pattern for the delimiter
pattern
,
String
opens the file with a specified charset
charset
,
Closure<T>
a closure
closure
)

Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern.

public static URI

Returns:

a URI
toURI
(CharSequence
the CharSequence representing a URI
self
)

Transforms a CharSequence representing a URI into a URI object.

public static URI

Returns:

a URI
toURI
(String
the String representing a URI
self
)

Transforms a String representing a URI into a URI object.

public static URL

Returns:

a URL
toURL
(CharSequence
the CharSequence representing a URL
self
)

Transforms a CharSequence representing a URL into a URL object.

public static URL

Returns:

a URL
toURL
(String
the String representing a URL
self
)

Transforms a String representing a URL into a URL object.

public static void
traverse(final File
a File (that happens to be a folder/directory)
self
,
final Map<String, ?>
a Map of options to alter the traversal behavior
options
,
final Closure<V>
the Closure to invoke on each file/directory and optionally returning a groovy.io.FileVisitResult value which can be used to control subsequent processing
closure
)

Processes each descendant file in this directory and any sub-directories.

public static void
traverse(final File
a File (that happens to be a folder/directory)
self
,
final Closure<V>
the Closure to invoke on each file/directory and optionally returning a groovy.io.FileVisitResult value which can be used to control subsequent processing
closure
)

Processes each descendant file in this directory and any sub-directories.

public static void
traverse(final File
a File (that happens to be a folder/directory)
self
,
final Map<String, ?>
a Map of options to alter the traversal behavior
options
)

Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree.

private static FileVisitResult
traverse(final File self, final Map<String, ?> options, final Closure<V> closure, final int maxDepth)

public static <T> T

Returns:

the value returned by the closure
withDataInputStream
(File
a File
file
,
Closure<T>
a closure
closure
)

Create a new DataInputStream for this file and passes it into the closure.

public static <T> T

Returns:

the value returned by the closure
withDataOutputStream
(File
a File
file
,
Closure<T>
a closure
closure
)

Create a new DataOutputStream for this file and passes it into the closure.

public static Object

Returns:

the value returned by the closure
withInputStream
(File
a File
file
,
Closure<V>
a closure
closure
)

Create a new InputStream for this file and passes it into the closure.

public static <T> T

Returns:

the value returned by the closure
withInputStream
(URL
a URL
url
,
Closure<T>
a closure
closure
)

Creates a new InputStream for this URL and passes it into the closure.

public static <T> T

Returns:

the value returned by the closure
withObjectInputStream
(File
a File
file
,
Closure<T>
a closure
closure
)

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

public static <T> T

Returns:

the value returned by the closure
withObjectInputStream
(File
a File
file
,
ClassLoader
the class loader to use when loading the class
classLoader
,
Closure<T>
a closure
closure
)

Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure.

public static <T> T

Returns:

the value returned by the closure
withObjectOutputStream
(File
a File
file
,
Closure<T>
a closure
closure
)

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

public static Object

Returns:

the value returned by the closure
withOutputStream
(File
a File
file
,
Closure<V>
a closure
closure
)

Creates a new OutputStream for this file and passes it into the closure.

public static <T> T

Returns:

the value returned by the closure
withPrintWriter
(File
a File
file
,
Closure<T>
the closure to invoke with the PrintWriter
closure
)

Create a new PrintWriter for this file which is then passed it into the given closure.

public static <T> T

Returns:

the value returned by the closure
withPrintWriter
(File
a File
file
,
String
the charset
charset
,
Closure<T>
the closure to invoke with the PrintWriter
closure
)

Create a new PrintWriter with a specified charset for this file.

public static <T> T

Returns:

the value returned by the closure
withReader
(File
a file object
file
,
Closure<T>
a closure
closure
)

Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns.

public static <T> T

Returns:

the value returned by the closure
withReader
(File
a file object
file
,
String
the charset for this input stream
charset
,
Closure<T>
a closure
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.

public static <T> T

Returns:

the value returned by the closure
withReader
(URL
a URL
url
,
Closure<T>
the closure to invoke with the reader
closure
)

Helper method to create a new BufferedReader for a URL and then passes it to the closure.

public static <T> T

Returns:

the value returned by the closure
withReader
(URL
a URL
url
,
String
the charset used
charset
,
Closure<T>
the closure to invoke with the reader
closure
)

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

public static <T> T

Returns:

the value returned by the closure
withWriter
(File
a File
file
,
Closure<T>
a closure
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.

public static <T> T

Returns:

the value returned by the closure
withWriter
(File
a File
file
,
String
the charset used
charset
,
Closure<T>
a closure
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.

public static <T> T

Returns:

the value returned by the closure
withWriterAppend
(File
a File
file
,
String
the charset used
charset
,
Closure<T>
a closure
closure
)

Create a new BufferedWriter which will append to this file.

public static <T> T

Returns:

the value returned by the closure
withWriterAppend
(File
a File
file
,
Closure<T>
a closure
closure
)

Create a new BufferedWriter for this file in append mode.

public static void
write(File
a File
file
,
String
the text to write to the File
text
)

Write the text to the File without writing a BOM.

public static void
write(File
a File
file
,
String
the text to write to the File
text
,
boolean
whether to write a BOM
writeBom
)

Write the text to the File.

public static void
write(File
a File
file
,
String
the text to write to the File
text
,
String
the charset used
charset
)

Write the text to the File without writing a BOM, using the specified encoding.

public static void
write(File
a File
file
,
String
the text to write to the File
text
,
String
the charset used
charset
,
boolean
whether to write a BOM
writeBom
)

Write the text to the File, using the specified encoding.

Inherited from org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport:
cloneSimilarCollectioncloneSimilarMapcloseQuietlycloseWithWarningcreateSimilarArraycreateSimilarCollectioncreateSimilarCollectioncreateSimilarCollectioncreateSimilarListcreateSimilarMapcreateSimilarOrDefaultCollectioncreateSimilarQueuecreateSimilarSetnormaliseIndexsameTypesubListBorderssubListBorderstryClosewriteUTF16BomIfRequiredwriteUTF16BomIfRequiredwriteUTF16BomIfRequiredwriteUTF16BomIfRequired