|
Groovy JDK |
Method Summary | |
---|---|
void
|
append(Object text)
Append the text at the end of the File |
void
|
append(byte[] bytes)
Append bytes to the end of a File |
void
|
append(Object text, String charset)
Append the text at the end of the File, using a specified encoding |
Object
|
asType(Class c)
Converts this File to a {@link Writable} or delegates to default {@link #asType(Object,Class)} |
File
|
asWritable()
Converts this File to a {@link Writable} |
File
|
asWritable(String encoding)
Allows a file to return a Writable implementation that can output itself to a Writer stream |
void
|
eachByte(Closure closure)
Traverse through each byte of this File |
void
|
eachDir(Closure closure)
Invokes the closure for each directory in this directory, ignoring regular files |
void
|
eachDirMatch(Object filter, Closure closure)
Invokes the closure for each directory whose name (dir - calling the isCase() method to determine if a match occurs with different kinds of filters like regular expressions, classes, ranges etc |
void
|
eachDirRecurse(Closure closure)
Invokes the closure for each descendant directory of this directory Sub-directories are recursively searched in a depth-first fashion Only directories are passed to the closure; regular files are ignored |
void
|
eachFile(Closure closure)
Invokes the closure for each file in the given directory |
void
|
eachFileMatch(Object filter, Closure closure)
Invokes the closure for each file whose name (file - calling the isCase() method to determine if a match occurs with different kinds of filters like regular expressions, classes, ranges etc |
void
|
eachFileRecurse(Closure closure)
Invokes the closure for each descendant file in this directory Sub-directories are recursively searched in a depth-first fashion |
Object
|
eachLine(Closure closure)
Iterates through this file line by line given 1 or 2 arg closure returns |
Object
|
eachLine(int firstLine, Closure closure)
Iterates through this file line by line to the given 1 or 2 arg closure before this method returns |
void
|
eachObject(Closure closure)
Iterates through the given file object by object |
Writable
|
filterLine(Closure closure)
Filters the lines of a File and creates a Writeable in return to stream the filtered lines |
void
|
filterLine(Writer writer, Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate |
String
|
getText(String charset)
Read the content of the File using the specified encoding and return it as a String |
String
|
getText()
Read the content of the File and returns it as a String |
Iterator
|
iterator()
Just throws a DeprecationException one line at a time |
File
|
leftShift(Object text)
Write the text to the File |
File
|
leftShift(byte[] bytes)
Write bytes to a File |
DataInputStream
|
newDataInputStream()
Create a data input stream for this file |
DataOutputStream
|
newDataOutputStream()
Creates a new data output stream for this file |
BufferedInputStream
|
newInputStream()
Creates a buffered input stream for this file |
ObjectInputStream
|
newObjectInputStream()
Create an object input stream for this file |
ObjectOutputStream
|
newObjectOutputStream()
Create an object output stream for this file |
BufferedOutputStream
|
newOutputStream()
Create a buffered output stream for this file |
PrintWriter
|
newPrintWriter()
Create a new PrintWriter for this file |
PrintWriter
|
newPrintWriter(String charset)
Create a new PrintWriter for this file, using specified charset |
BufferedReader
|
newReader()
Create a buffered reader for this file |
BufferedReader
|
newReader(String charset)
Create a buffered reader for this file, using the specified charset as the encoding |
BufferedWriter
|
newWriter()
Create a buffered writer for this file |
BufferedWriter
|
newWriter(boolean append)
Creates a buffered writer for this file, optionally appending to the existing file content |
BufferedWriter
|
newWriter(String charset, boolean append)
Helper method to create a buffered writer for a file charset is "UTF-16BE" or "UTF-16LE", the requisite byte order mark is written to the stream before the writer is returned |
BufferedWriter
|
newWriter(String charset)
Creates a buffered writer for this file, writing data using the given encoding |
byte[]
|
readBytes()
Reads the content of the file into a byte array |
List
|
readLines()
Reads the file into a list of Strings, with one item for each line |
void
|
setText(String text)
Synonym for write(text) allowing file |
long
|
size()
Provide the standard Groovy size() method for File
|
Object
|
splitEachLine(String sep, Closure closure)
Iterates through this file line by line, splitting on the seperator The list of tokens for each line is then passed to the given closure Finally the resources used for processing the file are closed |
Object
|
withDataInputStream(Closure closure)
Create a new DataInputStream for this file and passes it into the closure This method ensures the stream is closed after the closure returns |
Object
|
withDataOutputStream(Closure closure)
Create a new DataOutputStream for this file and passes it into the closure This method ensures the stream is closed after the closure returns |
Object
|
withInputStream(Closure closure)
Create a new InputStream for this file and passes it into the closure This method ensures the stream is closed after the closure returns |
Object
|
withObjectInputStream(Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure This method ensures the stream is closed after the closure returns |
Object
|
withObjectOutputStream(Closure closure)
Create a new ObjectOutputStream for this file and then pass it to the closure returns |
Object
|
withOutputStream(Closure closure)
Creates a new OutputStream for this file and passes it into the closure This method ensures the stream is closed after the closure returns |
Object
|
withPrintWriter(Closure closure)
Create a new PrintWriter for this file which is then passed it into the given closure is closed after the closure returns |
Object
|
withPrintWriter(String charset, Closure closure)
Create a new PrintWriter with a specified charset for this file before this method returns |
Object
|
withReader(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 |
Object
|
withReader(String charset, 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 |
Object
|
withWriter(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 |
Object
|
withWriter(String charset, 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 The writer will use the given charset encoding |
Object
|
withWriterAppend(String charset, Closure closure)
Create a new BufferedWriter which will append to this file this method returns |
Object
|
withWriterAppend(Closure closure)
Create a new BufferedWriter for this file in append mode is passed to the closure and is closed after the closure returns |
void
|
write(String text)
Write the text to the File |
void
|
write(String text, String charset)
Write the text to the File, using the specified encoding |
Method Detail |
---|
public void append(Object text)
text
- the text to append at the end of the File.
public void append(byte[] bytes)
bytes
- the byte array to append to the end of the File.
public void append(Object text, String charset)
text
- the text to append at the end of the File.
charset
- the charset used.
public Object asType(Class c)
c
- the desired class.
public File asWritable()
public File asWritable(String encoding)
encoding
- the encoding to be used when reading the file's contents.
public void eachByte(Closure closure)
closure
- a closure.
public void eachDir(Closure closure)
closure
- a closure.
public void eachDirMatch(Object filter, Closure closure)
filter
- the filter to perform on the directory (using the isCase(object) method).
closure
- the closure to invoke.
public void eachDirRecurse(Closure closure)
closure
- a closure.
public void eachFile(Closure closure)
closure
- a closure.
public void eachFileMatch(Object filter, Closure closure)
filter
- the filter to perform on the directory (using the isCase(object) method).
closure
- the closure to invoke.
public void eachFileRecurse(Closure closure)
closure
- a closure.
public Object eachLine(Closure closure)
closure
- a closure.
public Object eachLine(int firstLine, Closure closure)
firstLine
- the count of the first line.
closure
- a closure.
public void eachObject(Closure closure)
closure
- a closure.
public Writable filterLine(Closure closure)
closure
the
- a closure which returns a boolean indicating to filter
the line or not.
public void filterLine(Writer writer, Closure closure)
writer
- a writer destination to write filtered lines to.
closure
true
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer..
public String getText(String charset)
charset
- the charset used to read the content of the file.
public String getText()
public Iterator iterator()
public File leftShift(Object text)
text
- the text to write to the File.
public File leftShift(byte[] bytes)
bytes
- the byte array to append to the end of the File.
public DataInputStream newDataInputStream()
public DataOutputStream newDataOutputStream()
public BufferedInputStream newInputStream()
public ObjectInputStream newObjectInputStream()
public ObjectOutputStream newObjectOutputStream()
public BufferedOutputStream newOutputStream()
public PrintWriter newPrintWriter()
public PrintWriter newPrintWriter(String charset)
charset
- the charset.
public BufferedReader newReader()
public BufferedReader newReader(String charset)
charset
- the charset for this File.
public BufferedWriter newWriter()
public BufferedWriter newWriter(boolean append)
append
- true if data should be appended to the file.
public BufferedWriter newWriter(String charset, boolean append)
charset
- the name of the encoding used to write in this file.
append
- true if in append mode.
public BufferedWriter newWriter(String charset)
charset
- the name of the encoding used to write in this file.
public byte[] readBytes()
public List readLines()
public void setText(String text)
text
- the text to write to the File.
public long size()
size()
method for File
.
public Object splitEachLine(String sep, Closure closure)
sep
- a String separator.
closure
- a closure.
public Object withDataInputStream(Closure closure)
closure
- a closure.
public Object withDataOutputStream(Closure closure)
closure
- a closure.
public Object withInputStream(Closure closure)
closure
- a closure.
public Object withObjectInputStream(Closure closure)
closure
- a closure.
public Object withObjectOutputStream(Closure closure)
closure
- a closure.
public Object withOutputStream(Closure closure)
closure
- a closure.
public Object withPrintWriter(Closure closure)
closure
- the closure to invoke with the PrintWriter.
public Object withPrintWriter(String charset, Closure closure)
charset
- the charset.
closure
- the closure to invoke with the PrintWriter.
public Object withReader(Closure closure)
closure
- a closure.
public Object withReader(String charset, Closure closure)
charset
- the charset for this input stream.
closure
- a closure.
public Object withWriter(Closure closure)
closure
- a closure.
public Object withWriter(String charset, Closure closure)
charset
- the charset used.
closure
- a closure.
public Object withWriterAppend(String charset, Closure closure)
charset
- the charset used.
closure
- a closure.
public Object withWriterAppend(Closure closure)
closure
- a closure.
public void write(String text)
text
- the text to write to the File.
public void write(String text, String charset)
text
- the text to write to the File.
charset
- the charset used.
|
Groovy JDK |