org.codehaus.groovy.runtime
Class DefaultGroovyMethods

java.lang.Object
  extended byorg.codehaus.groovy.runtime.DefaultGroovyMethods

public class DefaultGroovyMethods
extends Object

This class defines all the new groovy methods which appear on normal JDK classes inside the Groovy environment. Static methods are used with the first parameter the destination class.

Version:
$Revision: 1.120 $
Author:
James Strachan, Jeremy Rayner, Sam Pullara, Rod Cope, Guillaume Laforge, John Wilson

Nested Class Summary
protected static class DefaultGroovyMethods.ProcessRunner
          A Runnable which waits for a process to complete together with a notification scheme allowing another thread to wait a maximum number of seconds for the process to complete before killing it.
 
Constructor Summary
DefaultGroovyMethods()
           
 
Method Summary
static double abs(Double number)
          Get the absolute value
static float abs(Float number)
          Get the absolute value
static long abs(Long number)
          Get the absolute value
static int abs(Number number)
          Get the absolute value
static Socket accept(ServerSocket serverSocket, groovy.lang.Closure closure)
          Allow to pass a Closure to the accept methods of ServerSocket
static List allProperties(Object self)
           
static Number and(Number left, Number right)
          Bitwise AND together two Numbers
static boolean any(Object self, groovy.lang.Closure closure)
          Iterates over every element of a collection, and check whether a predicate is valid for at least one element
static void append(File file, String text)
          Append the text at the end of the File
static void append(File file, String text, String charset)
          Append the text at the end of the File with a specified encoding
static Collection asImmutable(Collection self)
          A convenience method for creating an immutable Collection
static List asImmutable(List self)
          A convenience method for creating an immutable list
static Map asImmutable(Map self)
          A convenience method for creating an immutable map
static Set asImmutable(Set self)
          A convenience method for creating an immutable list
static SortedMap asImmutable(SortedMap self)
          A convenience method for creating an immutable sorted map
static SortedSet asImmutable(SortedSet self)
          A convenience method for creating an immutable sorted set
static List asList(Collection self)
          Converts the given collection into a List
static Collection asSynchronized(Collection self)
          A convenience method for creating a synchronized Collection
static List asSynchronized(List self)
          A convenience method for creating a synchronized List
static Map asSynchronized(Map self)
          A convenience method for creating a synchronized Map
static Set asSynchronized(Set self)
          A convenience method for creating a synchronized Set
static SortedMap asSynchronized(SortedMap self)
          A convenience method for creating a synchronized SortedMap
static SortedSet asSynchronized(SortedSet self)
          A convenience method for creating a synchronized SortedSet
static File asWritable(File file)
           
static File asWritable(File file, String encoding)
           
static String center(String self, Number numberOfChars)
          Center a String and padd it with spaces appended around it
static String center(String self, Number numberOfChars, String padding)
          Center a String and padd it with the characters appended around it
static List collect(Collection self, groovy.lang.Closure closure)
          Iterates through this collection transforming each entry into a new value using the closure as a transformer, returning a list of transformed values.
static List collect(Map self, groovy.lang.Closure closure)
          Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values.
static List collect(Object self, groovy.lang.Closure closure)
          Iterates through this object transforming each object into a new value using the closure as a transformer, returning a list of transformed values.
static int compareTo(Character left, Character right)
          Compare two Characters
static int compareTo(Character left, Number right)
          Compare a Character and a Number
static int compareTo(Number left, Character right)
          Compare a Number and a Character
static int compareTo(Number left, Number right)
          Compare two Numbers
static boolean contains(String self, String text)
          Provide an implementation of contains() like Collection to make Strings more polymorphic This method is not required on JDK 1.5 onwards
static int count(Collection self, Object value)
          Counts the number of occurencies of the given value inside this collection
static int count(String self, String text)
          Count the number of occurencies of a substring
protected static StringBufferWriter createStringBufferWriter(StringBuffer self)
           
protected static StringWriter createStringWriter(String self)
           
static byte[] decodeBase64(String value)
          Decode the Sting from base64 into a byte array
static Number div(Character left, Character right)
          Divide two Characters
static Number div(Character left, Number right)
          Divide a Character by a Number
static Number div(Number left, Character right)
          Divide a Number by a Character
static Number div(Number left, Number right)
          Divide two Numbers
static String dump(Object self)
          Generates a detailed dump string of an object showing its class, hashCode and fields
static void each(Collection self, groovy.lang.Closure closure)
          Allows objects to be iterated through using a closure
static void each(Map self, groovy.lang.Closure closure)
          Allows a Map to be iterated through using a closure.
static void each(Matcher matcher, groovy.lang.Closure closure)
           
static void each(Object self, groovy.lang.Closure closure)
          Allows objects to be iterated through using a closure
static void eachByte(File self, groovy.lang.Closure closure)
          Traverse through each byte of the specified File
static void eachByte(InputStream is, groovy.lang.Closure closure)
          Traverse through each byte of the specified stream
static void eachByte(URL url, groovy.lang.Closure closure)
          Traverse through each byte of the specified URL
static void eachFile(File self, groovy.lang.Closure closure)
          Invokes the closure for each file in the given directory
static void eachFileRecurse(File self, groovy.lang.Closure closure)
          Invokes the closure for each file in the given directory and recursively.
static void eachLine(File self, groovy.lang.Closure closure)
          Iterates through the given file line by line
static void eachLine(InputStream stream, groovy.lang.Closure closure)
          Iterates through the given stream line by line
static void eachLine(Reader self, groovy.lang.Closure closure)
          Iterates through the given reader line by line
static void eachLine(URL url, groovy.lang.Closure closure)
          Iterates through the lines read from the URL's associated input stream
static void eachMatch(String str, String regex, groovy.lang.Closure closure)
          process each regex matched substring of a string object.
static void eachProperty(Object self, groovy.lang.Closure closure)
           
static void eachPropertyName(Object self, groovy.lang.Closure closure)
           
static void eachWithIndex(Object self, groovy.lang.Closure closure)
          Allows object to be iterated through a closure with a counter
static groovy.lang.Writable encodeBase64(byte[] data)
          Produce a Writable object which writes the base64 encoding of the byte array Calling toString() on the result rerurns the encoding as a String
static groovy.lang.Writable encodeBase64(Byte[] data)
           
static boolean every(Object self, groovy.lang.Closure closure)
          Iterates over every element of a collection, and check whether a predicate is valid for all elements.
static Process execute(String self)
          Executes the given string as a command line process.
static groovy.lang.Writable filterLine(File self, groovy.lang.Closure closure)
          Filters the lines of a File and creates a Writeable in return to stream the filtered lines
static void filterLine(File self, Writer writer, groovy.lang.Closure closure)
          Filter the lines from a File and write them on a writer, according to a closure which returns true or false
static groovy.lang.Writable filterLine(InputStream self, groovy.lang.Closure predicate)
          Filter lines from an input stream using a closure predicate
static void filterLine(InputStream self, Writer writer, groovy.lang.Closure predicate)
          Filters lines from an input stream, writing to a writer, using a closure which returns boolean and takes a line.
static groovy.lang.Writable filterLine(Reader reader, groovy.lang.Closure closure)
          Filter the lines of a Reader and create a Writable in return to stream the filtered lines
static void filterLine(Reader reader, Writer writer, groovy.lang.Closure closure)
          Filter the lines from a reader and write them on the writer, according to a closure which returns true or false.
static Object find(Collection self, groovy.lang.Closure closure)
          Finds the first value matching the closure condition
static Object find(Map self, groovy.lang.Closure closure)
          Finds the first value matching the closure condition
static Object find(Object self, groovy.lang.Closure closure)
          Finds the first value matching the closure condition
static List findAll(Collection self, groovy.lang.Closure closure)
          Finds all values matching the closure condition
static List findAll(Map self, groovy.lang.Closure closure)
          Finds all values matching the closure condition
static List findAll(Object self, groovy.lang.Closure closure)
          Finds all values matching the closure condition
static int findIndexOf(Object self, groovy.lang.Closure closure)
          Iterates over every element of the collection and return the index of the first object that matches the condition specified in the closure
static List flatten(List self)
          Flatten a list
static Object get(Map map, Object key, Object defaultValue)
          Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.
static Object getAt(byte[] array, Collection indices)
           
static Object getAt(byte[] array, int idx)
           
static Object getAt(byte[] array, groovy.lang.Range range)
           
static Object getAt(char[] array, Collection indices)
           
static Object getAt(char[] array, int idx)
           
static Object getAt(char[] array, groovy.lang.Range range)
           
static CharSequence getAt(CharSequence self, Collection indices)
          Allows a List to be used as the indices to be used on a CharSequence
static CharSequence getAt(CharSequence text, int index)
          Support the subscript operator for String.
static CharSequence getAt(CharSequence text, groovy.lang.Range range)
          Support the range subscript operator for CharSequence
static List getAt(Collection coll, String property)
          Support the subscript operator for List
static Object getAt(double[] array, Collection indices)
           
static Object getAt(double[] array, int idx)
           
static Object getAt(double[] array, groovy.lang.Range range)
           
static Object getAt(float[] array, Collection indices)
           
static Object getAt(float[] array, int idx)
           
static Object getAt(float[] array, groovy.lang.Range range)
           
static Object getAt(int[] array, Collection indices)
           
static Object getAt(int[] array, int idx)
           
static Object getAt(int[] array, groovy.lang.Range range)
           
static List getAt(List self, Collection indices)
          Allows a List to be used as the indices to be used on a List
static Object getAt(List self, int idx)
          Support the subscript operator for a List
static List getAt(List self, groovy.lang.Range range)
          Support the range subscript operator for a List
static Object getAt(long[] array, Collection indices)
           
static Object getAt(long[] array, int idx)
           
static Object getAt(long[] array, groovy.lang.Range range)
           
static Object getAt(Map self, Object key)
          Support the subscript operator for a List
static String getAt(Matcher self, Collection indices)
          Allows a List to be used as the indices to be used on a Matcher
static String getAt(Matcher matcher, int idx)
          Support the subscript operator for a regex Matcher
static List getAt(Object[] self, Collection indices)
          Allows a List to be used as the indices to be used on a List
static Object getAt(Object[] array, int idx)
          Support the subscript operator for an Array
static List getAt(Object[] array, groovy.lang.Range range)
          Support the range subscript operator for an Array
static Object getAt(Object self, String property)
          Allows the subscript operator to be used to lookup dynamic property values.
static Object getAt(short[] array, Collection indices)
           
static Object getAt(short[] array, int idx)
           
static Object getAt(short[] array, groovy.lang.Range range)
           
static String getAt(String self, Collection indices)
          Allows a List to be used as the indices to be used on a String
static String getAt(String text, int index)
          Support the subscript operator for String
static String getAt(String text, groovy.lang.Range range)
          Support the range subscript operator for String
static InputStream getErr(Process self)
          An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar way
static InputStream getIn(Process self)
          An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar way
static OutputStream getOut(Process self)
          An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar way
static String getText(BufferedReader reader)
          Reads the content of the BufferedReader and returns it as a String
static String getText(File file)
          Reads the content of the File and returns it as a String
static String getText(File file, String charset)
          Reads the content of the File opened with the specified encoding and returns it as a String
static String getText(InputStream is)
          Reads the content of this InputStream and returns it as a String
static String getText(InputStream is, String charset)
          Reads the content of this InputStream with a specified charset and returns it as a String
static String getText(Process self)
          Read the text of the output stream of the Process.
static String getText(URL url)
          Reads the content of this URL and returns it as a String
static String getText(URL url, String charset)
          Reads the content of this URL and returns it as a String
static List grep(Object self, Object filter)
          Iterates over every element of the collection and return each object that matches the given filter - calling the isCase() method used by switch statements.
static Object inject(Collection self, Object value, groovy.lang.Closure closure)
          Iterates through the given collection, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure.
static String inspect(Object self)
           
static Number intdiv(Character left, Character right)
          Integer Divide two Characters
static Number intdiv(Character left, Number right)
          Integer Divide a Character by a Number
static Number intdiv(Number left, Character right)
          Integer Divide a Number by a Character
static Number intdiv(Number left, Number right)
          Integer Divide two Numbers
static List intersect(List left, Collection right)
          Create a List composed of the intersection of both collections
static Object invokeMethod(Object object, String method, Object arguments)
          Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.
static boolean isCase(Class caseValue, Object switchValue)
           
static boolean isCase(Collection caseValue, Object switchValue)
           
static boolean isCase(Object caseValue, Object switchValue)
           
static boolean isCase(Pattern caseValue, Object switchValue)
           
static boolean isCase(String caseValue, Object switchValue)
           
static String join(Collection self, String separator)
          Concatenates all of the items of the collection together with the given String as a separator
static String join(Object[] self, String separator)
          Concatenates all of the elements of the array together with the given String as a separator
static Collection leftShift(Collection self, Object value)
          Overloads the left shift operator to provide an easy way to append objects to a list
static Number leftShift(Number left, Number right)
          Implementation of the left shift operator for integral types.
static OutputStream leftShift(OutputStream self, byte[] value)
          Overloads the left shift operator to provide an append mechanism to add bytes to a stream
static Writer leftShift(OutputStream self, Object value)
          Overloads the left shift operator to provide an append mechanism to add things to a stream
static OutputStream leftShift(Process self, byte[] value)
          Overloads the left shift operator to provide an append mechanism to pipe into a Process
static Writer leftShift(Process self, Object value)
          Overloads the left shift operator to provide an append mechanism to pipe into a Process
static OutputStream leftShift(Socket self, byte[] value)
          Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket
static Writer leftShift(Socket self, Object value)
          Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket
static Writer leftShift(StringBuffer self, Object value)
          Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer
static StringWriter leftShift(String self, Object value)
          Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String
static Writer leftShift(Writer self, Object value)
          Overloads the left shift operator to provide an append mechanism to add things to a writer
static Object max(Collection self)
          Selects the maximum value found in the collection
static Object max(Collection self, groovy.lang.Closure closure)
          Selects the maximum value found in the collection using the given closure as a comparator
static Object max(Collection self, Comparator comparator)
          Selects the maximum value found in the collection using the given comparator
static Object min(Collection self)
          Selects the minimum value found in the collection
static Object min(Collection self, groovy.lang.Closure closure)
          Selects the minimum value found in the collection using the given closure as a comparator
static Object min(Collection self, Comparator comparator)
          Selects the minimum value found in the collection using the given comparator
static Number minus(Character left, Character right)
          Subtraction two Characters
static Number minus(Character left, Number right)
          Subtract a Number from a Character
static Date minus(Date self, int days)
          Subtracts a number of days from this date and returns the new date
static List minus(List self, Collection removeMe)
          Create a List composed of the elements of the first list minus the elements of the collection
static Number minus(Number left, Character right)
          Subtract a Character from a Number
static Number minus(Number left, Number right)
          Substraction of two Numbers
static String minus(String left, Object value)
          Remove a part of a String
static Number mod(Number left, Number right)
          Performs a division modulus operation
static Number multiply(Character left, Character right)
          Multiply two Characters
static Number multiply(Character left, Number right)
          Multiply a Character by a Number
static List multiply(Collection self, Number factor)
          Create a List composed of the same elements repeated a certain number of times.
static Number multiply(Number left, Character right)
          Multiply a Number by a Character
static Number multiply(Number left, Number right)
          Multiply two Numbers
static String multiply(String self, Number factor)
          Repeat a String a certain number of times
static Number negate(Number left)
          Negates the number
static BufferedInputStream newInputStream(File file)
          Helper method to create a buffered input stream for a file
static BufferedOutputStream newOutputStream(File file)
          Helper method to create a buffered output stream for a file
static PrintWriter newPrintWriter(File file)
          Helper method to create a new PrintWriter for a file
static PrintWriter newPrintWriter(File file, String charset)
          Helper method to create a new PrintWriter for a file with a specified charset
static BufferedReader newReader(File file)
          Helper method to create a buffered reader for a file
static BufferedReader newReader(File file, String charset)
          Helper method to create a buffered reader for a file, with a specified charset
static BufferedReader newReader(InputStream self)
          Provides a reader for an arbitrary input stream
static BufferedWriter newWriter(File file)
          Helper method to create a buffered writer for a file
static BufferedWriter newWriter(File file, boolean append)
          Helper method to create a buffered writer for a file in append mode
static BufferedWriter newWriter(File file, String charset)
          Helper method to create a buffered writer for a file
static BufferedWriter newWriter(File file, String charset, boolean append)
          Helper method to create a buffered writer for a file
static Number next(Character self)
          Increment a Character by one
static Date next(Date self)
          Increments a Date by a day
static Number next(Number self)
          Increment a Number by one
static String next(String self)
          Increments the last digit in the given string, resetting it and moving onto the next digit if increasing the digit no longer becomes a letter or digit.
protected static int normaliseIndex(int i, int size)
          This converts a possibly negative index to a real index into the array.
static Number or(Number left, Number right)
          Bitwise OR together two numbers
static String padLeft(String self, Number numberOfChars)
          Pad a String with the spaces appended to the left
static String padLeft(String self, Number numberOfChars, String padding)
          Pad a String with the characters appended to the left
static String padRight(String self, Number numberOfChars)
          Pad a String with the spaces appended to the right
static String padRight(String self, Number numberOfChars, String padding)
          Pad a String with the characters appended to the right
static Number plus(Character left, Character right)
          Add two Characters
static Number plus(Character left, Number right)
          Add a Character and a Number
static List plus(Collection left, Collection right)
          Create a List as a union of both Collections
static List plus(Collection left, Object right)
          Create a List as a union of a Collection and an Object
static Date plus(Date self, int days)
          Adds a number of days to this date and returns the new date
static Number plus(Number left, Character right)
          Add a Number and a Character
static Number plus(Number left, Number right)
          Add two Numbers
static String plus(Number value, String right)
          Appends a String
static String plus(String left, Object value)
          Appends a String
static Object pop(List self)
          Removes the last item from the List.
static Number power(Number self, Number exponent)
          Power of a Number to a certain exponent
static Number previous(Character self)
          Decrement a Character by one
static Date previous(Date self)
          Decrement a Date by a day
static Number previous(Number self)
          Decrement a Number by one
static String previous(String self)
          Decrements the last digit in the given string, resetting it and moving onto the next digit if increasing the digit no longer becomes a letter or digit.
protected static List primitiveArrayGet(Object self, Collection indices)
          Implements the getAt(Collection) method for primitve type arrays
protected static Object primitiveArrayGet(Object array, int idx)
          Implements the getAt(int) method for primitve type arrays
protected static List primitiveArrayGet(Object array, groovy.lang.Range range)
          Implements the getAt(Range) method for primitve type arrays
protected static void primitiveArrayPut(Object array, int idx, Object newValue)
          Implements the set(int idx) method for primitve type arrays
static void print(Object self, Object value)
          Print to a console in interactive format
static void print(Object self, PrintWriter out)
          Print to a console in interactive format
static void println(Object self, Object value)
          Print to a console in interactive format along with a newline
static void println(Object self, PrintWriter out)
          Print to a console in interactive format
static void putAt(byte[] array, int idx, Object newValue)
           
static void putAt(char[] array, int idx, Object newValue)
           
static void putAt(double[] array, int idx, Object newValue)
           
static void putAt(float[] array, int idx, Object newValue)
           
static void putAt(int[] array, int idx, Object newValue)
           
static void putAt(List self, int idx, Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(long[] array, int idx, Object newValue)
           
static Object putAt(Map self, Object key, Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(Object[] array, int idx, Object value)
          Support the subscript operator for an Array
static void putAt(Object self, String property, Object newValue)
          Allows the subscript operator to be used to set dynamically named property values.
static void putAt(short[] array, int idx, Object newValue)
           
static byte[] readBytes(File file)
          Reads the content of the file into an array of byte
static String readLine(InputStream stream)
          Read a single, whole line from the given InputStream
static String readLine(Reader self)
          Read a single, whole line from the given Reader
static List readLines(File file)
          Reads the file into a list of Strings for each line
static List readLines(InputStream stream)
          Reads the stream into a list of Strings for each line
static List readLines(Reader reader)
          Reads the reader into a list of Strings for each line
static List reverse(List self)
          Reverses the list
static String reverse(String self)
          Creates a new string which is the reverse (backwards) of this string
static void reverseEach(List self, groovy.lang.Closure closure)
          Iterate over each element of the list in the reverse order.
static Number rightShift(Number left, Number right)
          Implementation of the right shift operator for integral types.
static Number rightShiftUnsigned(Number left, Number right)
          Implementation of the right shift (unsigned) operator for integral types.
static long round(Double number)
          Round the value
static int round(Float number)
          Get the absolute value
static int size(byte[] array)
           
static int size(char[] array)
           
static int size(double[] array)
           
static int size(float[] array)
           
static int size(int[] array)
           
static int size(long[] array)
           
static int size(Object[] self)
          Makes an Array look like a Collection by adding support for the size() method
static int size(short[] array)
           
static int size(String text)
          Makes a String look like a Collection by adding support for the size() method
static List sort(Collection self)
          Sorts the given collection into a sorted list
static List sort(Collection self, groovy.lang.Closure closure)
          A convenience method for sorting a Collection using a closure as a comparator
static List sort(Collection self, Comparator comparator)
          A convenience method for sorting a Collection with a specific comparator
static List sort(List self)
          A convenience method for sorting a List
static List sort(List self, groovy.lang.Closure closure)
          A convenience method for sorting a List using a closure as a comparator
static List sort(List self, Comparator comparator)
          A convenience method for sorting a List with a specific comparator
static SortedSet sort(SortedSet self)
          Avoids doing unnecessary work when sorting an already sorted set
static void splitEachLine(File self, String sep, groovy.lang.Closure closure)
          Iterates through the given file line by line, splitting on the seperator
static void splitEachLine(Reader self, String sep, groovy.lang.Closure closure)
          Iterates through the given reader line by line, splitting on the seperator
static void step(Number self, Number to, Number stepNumber, groovy.lang.Closure closure)
          Iterates from this number up to the given number using a step increment
static Map subMap(Map map, Collection keys)
          Creates a sub-Map containing the given keys.
static void times(Number self, groovy.lang.Closure closure)
          Iterates a number of times
static Character toCharacter(String self)
          Converts the given string into a Character object using the first character in the string
static Double toDouble(String self)
          Parse a String into a Double
static Float toFloat(String self)
          Parse a String into a Float
static Integer toInteger(Number self)
          Transform a Number into an Integer
static Integer toInteger(String self)
          Parse a String into an Integer
static List tokenize(String self)
          Tokenize a String (with a whitespace as delimiter)
static List tokenize(String self, String token)
          Tokenize a String
static List toList(byte[] array)
           
static List toList(char[] array)
           
static List toList(Collection self)
          Convert a collection to a List.
static List toList(double[] array)
           
static List toList(float[] array)
           
static List toList(int[] array)
           
static List toList(long[] array)
           
static List toList(Object[] array)
          Allows conversion of arrays into a mutable List
static List toList(short[] array)
           
static List toList(String self)
          Converts the given String into a List of strings of one character
static Long toLong(String self)
          Parse a String into a Long
protected static String toString(Object value)
           
static URL toURL(String self)
          Transforms a String representing a URL into a URL object.
static void transformChar(Reader reader, Writer writer, groovy.lang.Closure closure)
          Transforms the characters from a reader with a Closure and write them to a writer
static void transformLine(Reader reader, Writer writer, groovy.lang.Closure closure)
          Transforms the lines from a reader with a Closure and write them to a writer
static void upto(Number self, Number to, groovy.lang.Closure closure)
          Iterates from this number up to the given number
static void use(Object self, Class categoryClass, groovy.lang.Closure closure)
          Scoped use method
static void use(Object self, List categoryClassList, groovy.lang.Closure closure)
          Scoped use method with list of categories
static void waitForOrKill(Process self, long numberOfMillis)
          Wait for the process to finish during a certain amount of time, otherwise stops the process.
static void withInputStream(File file, groovy.lang.Closure closure)
          Helper method to create a new InputStream for a file and then passes it into the closure and ensures its closed again afterwords
static void withOutputStream(File file, groovy.lang.Closure closure)
          Helper method to create a new OutputStream for a file and then passes it into the closure and ensures its closed again afterwords
static void withPrintWriter(File file, groovy.lang.Closure closure)
          Helper method to create a new PrintWriter for a file and then passes it into the closure and ensures its closed again afterwords
static void withReader(File file, groovy.lang.Closure closure)
          Helper method to create a new BufferedReader for a file and then passes it into the closure and ensures its closed again afterwords
static void withReader(InputStream in, groovy.lang.Closure closure)
          Helper method to create a new BufferedReader for a stream and then passes it into the closure and ensures its closed again afterwords
static void withReader(Reader writer, groovy.lang.Closure closure)
          Allows a Reader to be used, calling the closure with the writer and then ensuring that the writer is closed down again irrespective of whether exceptions occur or the
static void withReader(URL url, groovy.lang.Closure closure)
          Helper method to create a new BufferedReader for a URL and then passes it into the closure and ensures its closed again afterwords
static void withStream(InputStream stream, groovy.lang.Closure closure)
          Allows a InputStream to be used, calling the closure with the stream and then ensuring that the stream is closed down again irrespective of whether exceptions occur or the
static void withStream(OutputStream stream, groovy.lang.Closure closure)
          Allows a OutputStream to be used, calling the closure with the stream and then ensuring that the stream is closed down again irrespective of whether exceptions occur.
static void withStreams(Socket socket, groovy.lang.Closure closure)
          Allows an InputStream and an OutputStream from a Socket to be used, calling the closure with the streams and then ensuring that the streams are closed down again irrespective of whether exceptions occur.
static void withWriter(File file, groovy.lang.Closure closure)
          Helper method to create a new BufferedWriter for a file and then passes it into the closure and ensures it is closed again afterwords
static void withWriter(File file, String charset, groovy.lang.Closure closure)
          Helper method to create a new BufferedWriter for a file in a specified encoding and then passes it into the closure and ensures it is closed again afterwords
static void withWriter(OutputStream stream, groovy.lang.Closure closure)
          Allows an output stream to be used, calling the closure with the output stream and then ensuring that the output stream is closed down again irrespective of whether exceptions occur
static void withWriter(OutputStream stream, String charset, groovy.lang.Closure closure)
          Allows an output stream to be used, calling the closure with the output stream and then ensuring that the output stream is closed down again irrespective of whether exceptions occur.
static void withWriter(Writer writer, groovy.lang.Closure closure)
          Allows a writer to be used, calling the closure with the writer and then ensuring that the writer is closed down again irrespective of whether exceptions occur or the
static void withWriterAppend(File file, String charset, groovy.lang.Closure closure)
          Helper method to create a new BufferedWriter for a file in a specified encoding in append mode and then passes it into the closure and ensures it is closed again afterwords
static void write(File file, String text)
          Write the text to the File.
static void write(File file, String text, String charset)
          Write the text to the File with a specified encoding.
static void write(Writer self, groovy.lang.Writable writable)
          A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface.
static void writeLine(BufferedWriter writer, String line)
          Write the text and append a new line (depending on the platform line-ending)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultGroovyMethods

public DefaultGroovyMethods()
Method Detail

getAt

public static Object getAt(Object self,
                           String property)
Allows the subscript operator to be used to lookup dynamic property values. bean[somePropertyNameExpression]. The normal property notation of groovy is neater and more concise but only works with compile time known property names.

Parameters:
self -
Returns:

putAt

public static void putAt(Object self,
                         String property,
                         Object newValue)
Allows the subscript operator to be used to set dynamically named property values. bean[somePropertyNameExpression] = foo. The normal property notation of groovy is neater and more concise but only works with compile time known property names.

Parameters:
self -

dump

public static String dump(Object self)
Generates a detailed dump string of an object showing its class, hashCode and fields


eachPropertyName

public static void eachPropertyName(Object self,
                                    groovy.lang.Closure closure)

eachProperty

public static void eachProperty(Object self,
                                groovy.lang.Closure closure)

allProperties

public static List allProperties(Object self)

use

public static void use(Object self,
                       Class categoryClass,
                       groovy.lang.Closure closure)
Scoped use method


use

public static void use(Object self,
                       List categoryClassList,
                       groovy.lang.Closure closure)
Scoped use method with list of categories


print

public static void print(Object self,
                         Object value)
Print to a console in interactive format


println

public static void println(Object self,
                           Object value)
Print to a console in interactive format along with a newline


inspect

public static String inspect(Object self)
Returns:
a String that matches what would be typed into a terminal to create this object. e.g. [1, 'hello'].inspect() -> [1, "hello"]

print

public static void print(Object self,
                         PrintWriter out)
Print to a console in interactive format


println

public static void println(Object self,
                           PrintWriter out)
Print to a console in interactive format

Parameters:
out - the PrintWriter used for printing

invokeMethod

public static Object invokeMethod(Object object,
                                  String method,
                                  Object arguments)
Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.


isCase

public static boolean isCase(Object caseValue,
                             Object switchValue)

isCase

public static boolean isCase(String caseValue,
                             Object switchValue)

isCase

public static boolean isCase(Class caseValue,
                             Object switchValue)

isCase

public static boolean isCase(Collection caseValue,
                             Object switchValue)

isCase

public static boolean isCase(Pattern caseValue,
                             Object switchValue)

each

public static void each(Object self,
                        groovy.lang.Closure closure)
Allows objects to be iterated through using a closure

Parameters:
self - the object over which we iterate
closure - the closure applied on each element found

eachWithIndex

public static void eachWithIndex(Object self,
                                 groovy.lang.Closure closure)
Allows object to be iterated through a closure with a counter

Parameters:
self - an Object
closure - a Closure

each

public static void each(Collection self,
                        groovy.lang.Closure closure)
Allows objects to be iterated through using a closure

Parameters:
self - the collection over which we iterate
closure - the closure applied on each element of the collection

each

public static void each(Map self,
                        groovy.lang.Closure closure)
Allows a Map to be iterated through using a closure. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.

Parameters:
self - the map over which we iterate
closure - the closure applied on each entry of the map

every

public static boolean every(Object self,
                            groovy.lang.Closure closure)
Iterates over every element of a collection, and check whether a predicate is valid for all elements.

Parameters:
self - the object over which we iterate
closure - the closure predicate used for matching
Returns:
true if every item in the collection matches the closure predicate

any

public static boolean any(Object self,
                          groovy.lang.Closure closure)
Iterates over every element of a collection, and check whether a predicate is valid for at least one element

Parameters:
self - the object over which we iterate
closure - the closure predicate used for matching
Returns:
true if any item in the collection matches the closure predicate

grep

public static List grep(Object self,
                        Object filter)
Iterates over every element of the collection and return each object that matches the given filter - calling the isCase() method used by switch statements. This method can be used with different kinds of filters like regular expresions, classes, ranges etc.

Parameters:
self - the object over which we iterate
filter - the filter to perform on the collection (using the isCase(object) method)
Returns:
a list of objects which match the filter

count

public static int count(Collection self,
                        Object value)
Counts the number of occurencies of the given value inside this collection

Parameters:
self - the collection within which we count the number of occurencies
value - the value
Returns:
the number of occurrencies

toList

public static List toList(Collection self)
Convert a collection to a List.

Parameters:
self - a collection
Returns:
a List

collect

public static List collect(Object self,
                           groovy.lang.Closure closure)
Iterates through this object transforming each object into a new value using the closure as a transformer, returning a list of transformed values.

Parameters:
self - the values of the object to map
closure - the closure used to map each element of the collection
Returns:
a List of the mapped values

collect

public static List collect(Collection self,
                           groovy.lang.Closure closure)
Iterates through this collection transforming each entry into a new value using the closure as a transformer, returning a list of transformed values.

Parameters:
self - a collection
closure - the closure used for mapping
Returns:
a List of the mapped values

collect

public static List collect(Map self,
                           groovy.lang.Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values.

Parameters:
self - a Map
closure - the closure used for mapping
Returns:
a List of the mapped values

find

public static Object find(Object self,
                          groovy.lang.Closure closure)
Finds the first value matching the closure condition

Parameters:
self - an Object with an iterator returning its values
closure - a closure condition
Returns:
the first Object found

find

public static Object find(Collection self,
                          groovy.lang.Closure closure)
Finds the first value matching the closure condition

Parameters:
self - a Collection
closure - a closure condition
Returns:
the first Object found

find

public static Object find(Map self,
                          groovy.lang.Closure closure)
Finds the first value matching the closure condition

Parameters:
self - a Map
closure - a closure condition
Returns:
the first Object found

findAll

public static List findAll(Object self,
                           groovy.lang.Closure closure)
Finds all values matching the closure condition

Parameters:
self - an Object with an Iterator returning its values
closure - a closure condition
Returns:
a List of the values found

findAll

public static List findAll(Collection self,
                           groovy.lang.Closure closure)
Finds all values matching the closure condition

Parameters:
self - a Collection
closure - a closure condition
Returns:
a List of the values found

findAll

public static List findAll(Map self,
                           groovy.lang.Closure closure)
Finds all values matching the closure condition

Parameters:
self - a Map
closure - a closure condition applying on the keys
Returns:
a List of keys

inject

public static Object inject(Collection self,
                            Object value,
                            groovy.lang.Closure closure)
Iterates through the given collection, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure.

Parameters:
self - a Collection
value - a value
closure - a closure
Returns:
the last value of the last iteration

join

public static String join(Collection self,
                          String separator)
Concatenates all of the items of the collection together with the given String as a separator

Parameters:
self - a Collection of objects
separator - a String separator
Returns:
the joined String

join

public static String join(Object[] self,
                          String separator)
Concatenates all of the elements of the array together with the given String as a separator

Parameters:
self - an array of Object
separator - a String separator
Returns:
the joined String

max

public static Object max(Collection self)
Selects the maximum value found in the collection

Parameters:
self - a Collection
Returns:
the maximum value

max

public static Object max(Collection self,
                         Comparator comparator)
Selects the maximum value found in the collection using the given comparator

Parameters:
self - a Collection
comparator - a Comparator
Returns:
the maximum value

min

public static Object min(Collection self)
Selects the minimum value found in the collection

Parameters:
self - a Collection
Returns:
the minimum value

min

public static Object min(Collection self,
                         Comparator comparator)
Selects the minimum value found in the collection using the given comparator

Parameters:
self - a Collection
comparator - a Comparator
Returns:
the minimum value

min

public static Object min(Collection self,
                         groovy.lang.Closure closure)
Selects the minimum value found in the collection using the given closure as a comparator

Parameters:
self - a Collection
closure - a closure used as a comparator
Returns:
the minimum value

max

public static Object max(Collection self,
                         groovy.lang.Closure closure)
Selects the maximum value found in the collection using the given closure as a comparator

Parameters:
self - a Collection
closure - a closure used as a comparator
Returns:
the maximum value

size

public static int size(String text)
Makes a String look like a Collection by adding support for the size() method

Parameters:
text - a String
Returns:
the length of the String

size

public static int size(Object[] self)
Makes an Array look like a Collection by adding support for the size() method

Parameters:
self - an Array of Object
Returns:
the size of the Array

getAt

public static CharSequence getAt(CharSequence text,
                                 int index)
Support the subscript operator for String.

Parameters:
text - a String
index - the index of the Character to get
Returns:
the Character at the given index

getAt

public static String getAt(String text,
                           int index)
Support the subscript operator for String

Parameters:
text - a String
Returns:
the Character object at the given index

getAt

public static CharSequence getAt(CharSequence text,
                                 groovy.lang.Range range)
Support the range subscript operator for CharSequence

Parameters:
text - a CharSequence
range - a Range
Returns:
the subsequence CharSequence

getAt

public static String getAt(String text,
                           groovy.lang.Range range)
Support the range subscript operator for String

Parameters:
text - a String
range - a Range
Returns:
a substring corresponding to the Range

reverse

public static String reverse(String self)
Creates a new string which is the reverse (backwards) of this string

Parameters:
self - a String
Returns:
a new string with all the characters reversed.

toURL

public static URL toURL(String self)
                 throws MalformedURLException
Transforms a String representing a URL into a URL object.

Parameters:
self - the String representing a URL
Returns:
a URL
Throws:
MalformedURLException - is thrown if the URL is not well formed.

padLeft

public static String padLeft(String self,
                             Number numberOfChars,
                             String padding)
Pad a String with the characters appended to the left

Parameters:
numberOfChars - the total number of characters
padding - the charaters used for padding
Returns:
the String padded to the left

padLeft

public static String padLeft(String self,
                             Number numberOfChars)
Pad a String with the spaces appended to the left

Parameters:
numberOfChars - the total number of characters
Returns:
the String padded to the left

padRight

public static String padRight(String self,
                              Number numberOfChars,
                              String padding)
Pad a String with the characters appended to the right

Parameters:
numberOfChars - the total number of characters
padding - the charaters used for padding
Returns:
the String padded to the right

padRight

public static String padRight(String self,
                              Number numberOfChars)
Pad a String with the spaces appended to the right

Parameters:
numberOfChars - the total number of characters
Returns:
the String padded to the right

center

public static String center(String self,
                            Number numberOfChars,
                            String padding)
Center a String and padd it with the characters appended around it

Parameters:
numberOfChars - the total number of characters
padding - the charaters used for padding
Returns:
the String centered with padded character around

center

public static String center(String self,
                            Number numberOfChars)
Center a String and padd it with spaces appended around it

Parameters:
numberOfChars - the total number of characters
Returns:
the String centered with padded character around

getAt

public static String getAt(Matcher matcher,
                           int idx)
Support the subscript operator for a regex Matcher

Parameters:
matcher - a Matcher
idx - an index
Returns:
the group at the given index

getAt

public static List getAt(List self,
                         groovy.lang.Range range)
Support the range subscript operator for a List

Parameters:
self - a List
range - a Range
Returns:
a range of a list from the range's from index up to but not including the ranges's to value

getAt

public static List getAt(List self,
                         Collection indices)
Allows a List to be used as the indices to be used on a List

Parameters:
self - a List
indices - a Collection of indices
Returns:
a new list of the values at the given indices

getAt

public static List getAt(Object[] self,
                         Collection indices)
Allows a List to be used as the indices to be used on a List

Parameters:
self - an Array of Objects
indices - a Collection of indices
Returns:
a new list of the values at the given indices

getAt

public static CharSequence getAt(CharSequence self,
                                 Collection indices)
Allows a List to be used as the indices to be used on a CharSequence

Parameters:
self - a CharSequence
indices - a Collection of indices
Returns:
a String of the values at the given indices

getAt

public static String getAt(String self,
                           Collection indices)
Allows a List to be used as the indices to be used on a String

Parameters:
self - a String
indices - a Collection of indices
Returns:
a String of the values at the given indices

getAt

public static String getAt(Matcher self,
                           Collection indices)
Allows a List to be used as the indices to be used on a Matcher

Parameters:
self - a Matcher
indices - a Collection of indices
Returns:
a String of the values at the given indices

subMap

public static Map subMap(Map map,
                         Collection keys)
Creates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges.

Parameters:
map - a Map
keys - a Collection of keys
Returns:
a new Map containing the given keys

get

public static Object get(Map map,
                         Object key,
                         Object defaultValue)
Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.

Parameters:
map - a Map
key - the key to lookup the value of
defaultValue - the value to return and add to the map for this key if there is no entry for the given key
Returns:
the value of the given key or the default value, added to the map if the key did not exist

getAt

public static List getAt(Object[] array,
                         groovy.lang.Range range)
Support the range subscript operator for an Array

Parameters:
array - an Array of Objects
range - a Range
Returns:
a range of a list from the range's from index up to but not including the ranges's to value

getAt

public static Object getAt(Object[] array,
                           int idx)
Support the subscript operator for an Array

Parameters:
array - an Array of Objects
idx - an index
Returns:
the value at the given index

putAt

public static void putAt(Object[] array,
                         int idx,
                         Object value)
Support the subscript operator for an Array

Parameters:
array - an Array of Objects
idx - an index
value - an Object to put at the given index

toList

public static List toList(Object[] array)
Allows conversion of arrays into a mutable List

Parameters:
array - an Array of Objects
Returns:
the array as a List

getAt

public static Object getAt(List self,
                           int idx)
Support the subscript operator for a List

Parameters:
self - a List
idx - an index
Returns:
the value at the given index

putAt

public static void putAt(List self,
                         int idx,
                         Object value)
A helper method to allow lists to work with subscript operators

Parameters:
self - a List
idx - an index
value - the value to put at the given index

getAt

public static Object getAt(Map self,
                           Object key)
Support the subscript operator for a List

Parameters:
self - a Map
key - an Object as a key for the map
Returns:
the value corresponding to the given key

putAt

public static Object putAt(Map self,
                           Object key,
                           Object value)
A helper method to allow lists to work with subscript operators

Parameters:
self - a Map
key - an Object as a key for the map
Returns:
the value corresponding to the given key

normaliseIndex

protected static int normaliseIndex(int i,
                                    int size)
This converts a possibly negative index to a real index into the array.

Parameters:
i -
size -
Returns:

getAt

public static List getAt(Collection coll,
                         String property)
Support the subscript operator for List

Parameters:
coll - a Collection
property - a String
Returns:
a List

asImmutable

public static Map asImmutable(Map self)
A convenience method for creating an immutable map

Parameters:
self - a Map
Returns:
an immutable Map

asImmutable

public static SortedMap asImmutable(SortedMap self)
A convenience method for creating an immutable sorted map

Parameters:
self - a SortedMap
Returns:
an immutable SortedMap

asImmutable

public static List asImmutable(List self)
A convenience method for creating an immutable list

Parameters:
self - a List
Returns:
an immutable List

asImmutable

public static Set asImmutable(Set self)
A convenience method for creating an immutable list

Parameters:
self - a Set
Returns:
an immutable Set

asImmutable

public static SortedSet asImmutable(SortedSet self)
A convenience method for creating an immutable sorted set

Parameters:
self - a SortedSet
Returns:
an immutable SortedSet

asImmutable

public static Collection asImmutable(Collection self)
A convenience method for creating an immutable Collection

Parameters:
self - a Collection
Returns:
an immutable Collection

asSynchronized

public static Map asSynchronized(Map self)
A convenience method for creating a synchronized Map

Parameters:
self - a Map
Returns:
a synchronized Map

asSynchronized

public static SortedMap asSynchronized(SortedMap self)
A convenience method for creating a synchronized SortedMap

Parameters:
self - a SortedMap
Returns:
a synchronized SortedMap

asSynchronized

public static Collection asSynchronized(Collection self)
A convenience method for creating a synchronized Collection

Parameters:
self - a Collection
Returns:
a synchronized Collection

asSynchronized

public static List asSynchronized(List self)
A convenience method for creating a synchronized List

Parameters:
self - a List
Returns:
a synchronized List

asSynchronized

public static Set asSynchronized(Set self)
A convenience method for creating a synchronized Set

Parameters:
self - a Set
Returns:
a synchronized Set

asSynchronized

public static SortedSet asSynchronized(SortedSet self)
A convenience method for creating a synchronized SortedSet

Parameters:
self - a SortedSet
Returns:
a synchronized SortedSet

sort

public static List sort(Collection self)
Sorts the given collection into a sorted list

Parameters:
self - the collection to be sorted
Returns:
the sorted collection as a List

sort

public static SortedSet sort(SortedSet self)
Avoids doing unnecessary work when sorting an already sorted set

Parameters:
self -
Returns:
the sorted set

sort

public static List sort(List self)
A convenience method for sorting a List

Parameters:
self - a List to be sorted
Returns:
the sorted List

pop

public static Object pop(List self)
Removes the last item from the List. Using add() and pop() is similar to push and pop on a Stack.

Parameters:
self - a List
Returns:
the item removed from the List
Throws:
UnsupportedOperationException - if the list is empty and you try to pop() it.

sort

public static List sort(List self,
                        Comparator comparator)
A convenience method for sorting a List with a specific comparator

Parameters:
self - a List
comparator - a Comparator used for the comparison
Returns:
a sorted List

sort

public static List sort(Collection self,
                        Comparator comparator)
A convenience method for sorting a Collection with a specific comparator

Parameters:
self - a collection to be sorted
comparator - a Comparator used for the comparison
Returns:
a newly created sorted List

sort

public static List sort(List self,
                        groovy.lang.Closure closure)
A convenience method for sorting a List using a closure as a comparator

Parameters:
self - a List
closure - a Closure used as a comparator
Returns:
a sorted List

sort

public static List sort(Collection self,
                        groovy.lang.Closure closure)
A convenience method for sorting a Collection using a closure as a comparator

Parameters:
self - a Collection to be sorted
closure - a Closure used as a comparator
Returns:
a newly created sorted List

asList

public static List asList(Collection self)
Converts the given collection into a List

Parameters:
self - a collection to be converted into a List
Returns:
a newly created List if this collection is not already a List

reverse

public static List reverse(List self)
Reverses the list

Parameters:
self - a List
Returns:
a reversed List

plus

public static List plus(Collection left,
                        Collection right)
Create a List as a union of both Collections

Parameters:
left - the left Collection
right - the right Collection
Returns:
a List

plus

public static List plus(Collection left,
                        Object right)
Create a List as a union of a Collection and an Object

Parameters:
left - a Collection
right - an object to append
Returns:
a List

multiply

public static List multiply(Collection self,
                            Number factor)
Create a List composed of the same elements repeated a certain number of times.

Parameters:
self - a Collection
factor - the number of times to append
Returns:
a List

intersect

public static List intersect(List left,
                             Collection right)
Create a List composed of the intersection of both collections

Parameters:
left - a List
right - a Collection
Returns:
a List as an intersection of both collections

minus

public static List minus(List self,
                         Collection removeMe)
Create a List composed of the elements of the first list minus the elements of the collection

Parameters:
self - a List
removeMe - a Collection of elements to remove
Returns:
a List with the common elements removed

flatten

public static List flatten(List self)
Flatten a list

Parameters:
self - a List
Returns:
a flattened List

reverseEach

public static void reverseEach(List self,
                               groovy.lang.Closure closure)
Iterate over each element of the list in the reverse order.

Parameters:
self - a List
closure - a closure

leftShift

public static Collection leftShift(Collection self,
                                   Object value)
Overloads the left shift operator to provide an easy way to append objects to a list

Parameters:
self - a Collection
value - an Object to be added to the collection.
Returns:
a Collection with an Object added to it.

leftShift

public static StringWriter leftShift(String self,
                                     Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String

Parameters:
self - a String
value - an Obect
Returns:
a StringWriter

createStringWriter

protected static StringWriter createStringWriter(String self)

createStringBufferWriter

protected static StringBufferWriter createStringBufferWriter(StringBuffer self)

leftShift

public static Writer leftShift(StringBuffer self,
                               Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer

Parameters:
self - a StringBuffer
value - a value to append
Returns:
a StringWriter

leftShift

public static Writer leftShift(Writer self,
                               Object value)
                        throws IOException
Overloads the left shift operator to provide an append mechanism to add things to a writer

Parameters:
self - a Writer
value - a value to append
Returns:
a StringWriter
Throws:
IOException

leftShift

public static Number leftShift(Number left,
                               Number right)
Implementation of the left shift operator for integral types. Non integral Number types throw UnsupportedOperationException.


rightShift

public static Number rightShift(Number left,
                                Number right)
Implementation of the right shift operator for integral types. Non integral Number types throw UnsupportedOperationException.


rightShiftUnsigned

public static Number rightShiftUnsigned(Number left,
                                        Number right)
Implementation of the right shift (unsigned) operator for integral types. Non integral Number types throw UnsupportedOperationException.


write

public static void write(Writer self,
                         groovy.lang.Writable writable)
                  throws IOException
A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface.

Parameters:
self - a Writer
writable - an object implementing the Writable interface
Throws:
IOException

leftShift

public static Writer leftShift(OutputStream self,
                               Object value)
                        throws IOException
Overloads the left shift operator to provide an append mechanism to add things to a stream

Parameters:
self - an OutputStream
value - a value to append
Returns:
a Writer
Throws:
IOException

leftShift

public static OutputStream leftShift(OutputStream self,
                                     byte[] value)
                              throws IOException
Overloads the left shift operator to provide an append mechanism to add bytes to a stream

Parameters:
self - an OutputStream
value - a value to append
Returns:
an OutputStream
Throws:
IOException

getAt

public static Object getAt(byte[] array,
                           int idx)

getAt

public static Object getAt(char[] array,
                           int idx)

getAt

public static Object getAt(short[] array,
                           int idx)

getAt

public static Object getAt(int[] array,
                           int idx)

getAt

public static Object getAt(long[] array,
                           int idx)

getAt

public static Object getAt(float[] array,
                           int idx)

getAt

public static Object getAt(double[] array,
                           int idx)

getAt

public static Object getAt(byte[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(char[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(short[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(int[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(long[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(float[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(double[] array,
                           groovy.lang.Range range)

getAt

public static Object getAt(byte[] array,
                           Collection indices)

getAt

public static Object getAt(char[] array,
                           Collection indices)

getAt

public static Object getAt(short[] array,
                           Collection indices)

getAt

public static Object getAt(int[] array,
                           Collection indices)

getAt

public static Object getAt(long[] array,
                           Collection indices)

getAt

public static Object getAt(float[] array,
                           Collection indices)

getAt

public static Object getAt(double[] array,
                           Collection indices)

putAt

public static void putAt(byte[] array,
                         int idx,
                         Object newValue)

putAt

public static void putAt(char[] array,
                         int idx,
                         Object newValue)

putAt

public static void putAt(short[] array,
                         int idx,
                         Object newValue)

putAt

public static void putAt(int[] array,
                         int idx,
                         Object newValue)

putAt

public static void putAt(long[] array,
                         int idx,
                         Object newValue)

putAt

public static void putAt(float[] array,
                         int idx,
                         Object newValue)

putAt

public static void putAt(double[] array,
                         int idx,
                         Object newValue)

size

public static int size(byte[] array)

size

public static int size(char[] array)

size

public static int size(short[] array)

size

public static int size(int[] array)

size

public static int size(long[] array)

size

public static int size(float[] array)

size

public static int size(double[] array)

toList

public static List toList(byte[] array)

toList

public static List toList(char[] array)

toList

public static List toList(short[] array)

toList

public static List toList(int[] array)

toList

public static List toList(long[] array)

toList

public static List toList(float[] array)

toList

public static List toList(double[] array)

encodeBase64

public static groovy.lang.Writable encodeBase64(Byte[] data)

encodeBase64

public static groovy.lang.Writable encodeBase64(byte[] data)
Produce a Writable object which writes the base64 encoding of the byte array Calling toString() on the result rerurns the encoding as a String

Parameters:
data - byte array to be encoded
Returns:
object which will write the base64 encoding of the byte array

decodeBase64

public static byte[] decodeBase64(String value)
Decode the Sting from base64 into a byte array

Parameters:
value - the string to be decoded
Returns:
the decoded bytes as an array

primitiveArrayGet

protected static Object primitiveArrayGet(Object array,
                                          int idx)
Implements the getAt(int) method for primitve type arrays


primitiveArrayGet

protected static List primitiveArrayGet(Object array,
                                        groovy.lang.Range range)
Implements the getAt(Range) method for primitve type arrays


primitiveArrayGet

protected static List primitiveArrayGet(Object self,
                                        Collection indices)
Implements the getAt(Collection) method for primitve type arrays


primitiveArrayPut

protected static void primitiveArrayPut(Object array,
                                        int idx,
                                        Object newValue)
Implements the set(int idx) method for primitve type arrays


toCharacter

public static Character toCharacter(String self)
Converts the given string into a Character object using the first character in the string

Parameters:
self - a String
Returns:
the first Character

tokenize

public static List tokenize(String self,
                            String token)
Tokenize a String

Parameters:
self - a String
token - the delimiter
Returns:
a List of tokens

tokenize

public static List tokenize(String self)
Tokenize a String (with a whitespace as delimiter)

Parameters:
self - a String
Returns:
a List of tokens

plus

public static String plus(String left,
                          Object value)
Appends a String

Parameters:
left - a String
value - a String
Returns:
a String

plus

public static String plus(Number value,
                          String right)
Appends a String

Parameters:
value - a Number
right - a String
Returns:
a String

minus

public static String minus(String left,
                           Object value)
Remove a part of a String

Parameters:
left - a String
value - a String part to remove
Returns:
a String minus the part to be removed

contains

public static boolean contains(String self,
                               String text)
Provide an implementation of contains() like Collection to make Strings more polymorphic This method is not required on JDK 1.5 onwards

Parameters:
self - a String
text - a String to look for
Returns:
true if this string contains the given text

count

public static int count(String self,
                        String text)
Count the number of occurencies of a substring

Parameters:
self - a String
text - a substring
Returns:
the number of occurrencies of the given string inside this String

next

public static String next(String self)
Increments the last digit in the given string, resetting it and moving onto the next digit if increasing the digit no longer becomes a letter or digit.

Parameters:
self - a String
Returns:
a String with an incremented digit at the end

previous

public static String previous(String self)
Decrements the last digit in the given string, resetting it and moving onto the next digit if increasing the digit no longer becomes a letter or digit.

Parameters:
self - a String
Returns:
a String with a decremented digit at the end

execute

public static Process execute(String self)
                       throws IOException
Executes the given string as a command line process. For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder.

Parameters:
self - a command line String
Returns:
the Process which has just started for this command line string
Throws:
IOException

multiply

public static String multiply(String self,
                              Number factor)
Repeat a String a certain number of times

Parameters:
self - a String to be repeated
factor - the number of times the String should be repeated
Returns:
a String composed of a repeatition
Throws:
IllegalArgumentException - if the number of repeatition is < 0

toString

protected static String toString(Object value)

next

public static Number next(Character self)
Increment a Character by one

Parameters:
self - a Character
Returns:
an incremented Number

next

public static Number next(Number self)
Increment a Number by one

Parameters:
self - a Number
Returns:
an incremented Number

previous

public static Number previous(Character self)
Decrement a Character by one

Parameters:
self - a Character
Returns:
a decremented Number

previous

public static Number previous(Number self)
Decrement a Number by one

Parameters:
self - a Number
Returns:
a decremented Number

plus

public static Number plus(Character left,
                          Number right)
Add a Character and a Number

Parameters:
left - a Character
right - a Number
Returns:
the addition of the Character and the Number

plus

public static Number plus(Number left,
                          Character right)
Add a Number and a Character

Parameters:
left - a Number
right - a Character
Returns:
the addition of the Character and the Number

plus

public static Number plus(Character left,
                          Character right)
Add two Characters

Parameters:
left - a Character
right - a Character
Returns:
the addition of both Characters

plus

public static Number plus(Number left,
                          Number right)
Add two Numbers

Parameters:
left - a Number
right - another Number to add
Returns:
the addition of both Numbers

compareTo

public static int compareTo(Character left,
                            Number right)
Compare a Character and a Number

Parameters:
left - a Character
right - a Number
Returns:
the result of the comparison

compareTo

public static int compareTo(Number left,
                            Character right)
Compare a Number and a Character

Parameters:
left - a Number
right - a Character
Returns:
the result of the comparison

compareTo

public static int compareTo(Character left,
                            Character right)
Compare two Characters

Parameters:
left - a Character
right - a Character
Returns:
the result of the comparison

compareTo

public static int compareTo(Number left,
                            Number right)
Compare two Numbers

Parameters:
left - a Number
right - another Number to compare to
Returns:
the comparision of both numbers

minus

public static Number minus(Character left,
                           Number right)
Subtract a Number from a Character

Parameters:
left - a Character
right - a Number
Returns:
the addition of the Character and the Number

minus

public static Number minus(Number left,
                           Character right)
Subtract a Character from a Number

Parameters:
left - a Number
right - a Character
Returns:
the addition of the Character and the Number

minus

public static Number minus(Character left,
                           Character right)
Subtraction two Characters

Parameters:
left - a Character
right - a Character
Returns:
the addition of both Characters

minus

public static Number minus(Number left,
                           Number right)
Substraction of two Numbers

Parameters:
left - a Number
right - another Number to substract to the first one
Returns:
the substraction

multiply

public static Number multiply(Character left,
                              Number right)
Multiply a Character by a Number

Parameters:
left - a Character
right - a Number
Returns:
the multiplication of both

multiply

public static Number multiply(Number left,
                              Character right)
Multiply a Number by a Character

Parameters:
left - a Number
right - a Character
Returns:
the multiplication of both

multiply

public static Number multiply(Character left,
                              Character right)
Multiply two Characters

Parameters:
left - a Character
right - another Character
Returns:
the multiplication of both

multiply

public static Number multiply(Number left,
                              Number right)
Multiply two Numbers

Parameters:
left - a Number
right - another Number
Returns:
the multiplication of both

power

public static Number power(Number self,
                           Number exponent)
Power of a Number to a certain exponent

Parameters:
self - a Number
exponent - a Number exponent
Returns:
a Number to the power of a certain exponent

div

public static Number div(Character left,
                         Number right)
Divide a Character by a Number

Parameters:
left - a Character
right - a Number
Returns:
the multiplication of both

div

public static Number div(Number left,
                         Character right)
Divide a Number by a Character

Parameters:
left - a Number
right - a Character
Returns:
the multiplication of both

div

public static Number div(Character left,
                         Character right)
Divide two Characters

Parameters:
left - a Character
right - another Character
Returns:
the multiplication of both

div

public static Number div(Number left,
                         Number right)
Divide two Numbers

Parameters:
left - a Number
right - another Number
Returns:
a Number resulting of the divide operation

intdiv

public static Number intdiv(Character left,
                            Number right)
Integer Divide a Character by a Number

Parameters:
left - a Character
right - a Number
Returns:
the integer division of both

intdiv

public static Number intdiv(Number left,
                            Character right)
Integer Divide a Number by a Character

Parameters:
left - a Number
right - a Character
Returns:
the integer division of both

intdiv

public static Number intdiv(Character left,
                            Character right)
Integer Divide two Characters

Parameters:
left - a Character
right - another Character
Returns:
the integer division of both

intdiv

public static Number intdiv(Number left,
                            Number right)
Integer Divide two Numbers

Parameters:
left - a Number
right - another Number
Returns:
a Number (an Integer) resulting of the integer division operation

or

public static Number or(Number left,
                        Number right)
Bitwise OR together two numbers

Parameters:
left - a Number
right - another Number to bitwise OR
Returns:
the bitwise OR of both Numbers

and

public static Number and(Number left,
                         Number right)
Bitwise AND together two Numbers

Parameters:
left - a Number
right - another Number to bitwse AND
Returns:
the bitwise AND of both Numbers

mod

public static Number mod(Number left,
                         Number right)
Performs a division modulus operation

Parameters:
left - a Number
right - another Number to mod
Returns:
the modulus result

negate

public static Number negate(Number left)
Negates the number

Parameters:
left - a Number
Returns:
the negation of the number

times

public static void times(Number self,
                         groovy.lang.Closure closure)
Iterates a number of times

Parameters:
self - a Number
closure - the closure to call a number of times

upto

public static void upto(Number self,
                        Number to,
                        groovy.lang.Closure closure)
Iterates from this number up to the given number

Parameters:
self - a Number
to - another Number to go up to
closure - the closure to call

step

public static void step(Number self,
                        Number to,
                        Number stepNumber,
                        groovy.lang.Closure closure)
Iterates from this number up to the given number using a step increment

Parameters:
self - a Number to start with
to - a Number to go up to
stepNumber - a Number representing the step increment
closure - the closure to call

abs

public static int abs(Number number)
Get the absolute value

Parameters:
number - a Number
Returns:
the absolute value of that Number

abs

public static long abs(Long number)
Get the absolute value

Parameters:
number - a Long
Returns:
the absolute value of that Long

abs

public static float abs(Float number)
Get the absolute value

Parameters:
number - a Float
Returns:
the absolute value of that Float

abs

public static double abs(Double number)
Get the absolute value

Parameters:
number - a Double
Returns:
the absolute value of that Double

round

public static int round(Float number)
Get the absolute value

Parameters:
number - a Float
Returns:
the absolute value of that Float

round

public static long round(Double number)
Round the value

Parameters:
number - a Double
Returns:
the absolute value of that Double

toInteger

public static Integer toInteger(String self)
Parse a String into an Integer

Parameters:
self - a String
Returns:
an Integer

toLong

public static Long toLong(String self)
Parse a String into a Long

Parameters:
self - a String
Returns:
a Long

toFloat

public static Float toFloat(String self)
Parse a String into a Float

Parameters:
self - a String
Returns:
a Float

toDouble

public static Double toDouble(String self)
Parse a String into a Double

Parameters:
self - a String
Returns:
a Double

toInteger

public static Integer toInteger(Number self)
Transform a Number into an Integer

Parameters:
self - a Number
Returns:
an Integer

next

public static Date next(Date self)
Increments a Date by a day

Parameters:
self - a Date
Returns:
the next days date

previous

public static Date previous(Date self)
Decrement a Date by a day

Parameters:
self - a Date
Returns:
the previous days date

plus

public static Date plus(Date self,
                        int days)
Adds a number of days to this date and returns the new date

Parameters:
self - a Date
days - the number of days to increase
Returns:
the new date

minus

public static Date minus(Date self,
                         int days)
Subtracts a number of days from this date and returns the new date

Parameters:
self - a Date
Returns:
the new date

eachLine

public static void eachLine(File self,
                            groovy.lang.Closure closure)
                     throws IOException
Iterates through the given file line by line

Parameters:
self - a File
closure - a closure
Throws:
IOException

eachLine

public static void eachLine(Reader self,
                            groovy.lang.Closure closure)
                     throws IOException
Iterates through the given reader line by line

Parameters:
self - a Reader
closure - a closure
Throws:
IOException

splitEachLine

public static void splitEachLine(File self,
                                 String sep,
                                 groovy.lang.Closure closure)
                          throws IOException
Iterates through the given file line by line, splitting on the seperator

Parameters:
self - a File
sep - a String separator
closure - a closure
Throws:
IOException

splitEachLine

public static void splitEachLine(Reader self,
                                 String sep,
                                 groovy.lang.Closure closure)
                          throws IOException
Iterates through the given reader line by line, splitting on the seperator

Parameters:
self - a Reader
sep - a String separator
closure - a closure
Throws:
IOException

readLine

public static String readLine(Reader self)
                       throws IOException
Read a single, whole line from the given Reader

Parameters:
self - a Reader
Returns:
a line
Throws:
IOException

readLine

public static String readLine(InputStream stream)
                       throws IOException
Read a single, whole line from the given InputStream

Parameters:
stream - an InputStream
Returns:
a line
Throws:
IOException

readLines

public static List readLines(File file)
                      throws IOException
Reads the file into a list of Strings for each line

Parameters:
file - a File
Returns:
a List of lines
Throws:
IOException

getText

public static String getText(File file,
                             String charset)
                      throws IOException
Reads the content of the File opened with the specified encoding and returns it as a String

Parameters:
file - the file whose content we want to read
charset - the charset used to read the content of the file
Returns:
a String containing the content of the file
Throws:
IOException

getText

public static String getText(File file)
                      throws IOException
Reads the content of the File and returns it as a String

Parameters:
file - the file whose content we want to read
Returns:
a String containing the content of the file
Throws:
IOException

getText

public static String getText(URL url)
                      throws IOException
Reads the content of this URL and returns it as a String

Parameters:
url - URL to read content from
Returns:
the text from that URL
Throws:
IOException

getText

public static String getText(URL url,
                             String charset)
                      throws IOException
Reads the content of this URL and returns it as a String

Parameters:
url - URL to read content from
charset - opens the stream with a specified charset
Returns:
the text from that URL
Throws:
IOException

getText

public static String getText(InputStream is)
                      throws IOException
Reads the content of this InputStream and returns it as a String

Parameters:
is - an input stream
Returns:
the text from that URL
Throws:
IOException

getText

public static String getText(InputStream is,
                             String charset)
                      throws IOException
Reads the content of this InputStream with a specified charset and returns it as a String

Parameters:
is - an input stream
charset - opens the stream with a specified charset
Returns:
the text from that URL
Throws:
IOException

getText

public static String getText(BufferedReader reader)
                      throws IOException
Reads the content of the BufferedReader and returns it as a String

Parameters:
reader - a BufferedReader whose content we want to read
Returns:
a String containing the content of the buffered reader
Throws:
IOException

writeLine

public static void writeLine(BufferedWriter writer,
                             String line)
                      throws IOException
Write the text and append a new line (depending on the platform line-ending)

Parameters:
writer - a BufferedWriter
line - the line to write
Throws:
IOException

write

public static void write(File file,
                         String text)
                  throws IOException
Write the text to the File.

Parameters:
file - a File
text - the text to write to the File
Throws:
IOException

write

public static void write(File file,
                         String text,
                         String charset)
                  throws IOException
Write the text to the File with a specified encoding.

Parameters:
file - a File
text - the text to write to the File
charset - the charset used
Throws:
IOException

append

public static void append(File file,
                          String text)
                   throws IOException
Append the text at the end of the File

Parameters:
file - a File
text - the text to append at the end of the File
Throws:
IOException

append

public static void append(File file,
                          String text,
                          String charset)
                   throws IOException
Append the text at the end of the File with a specified encoding

Parameters:
file - a File
text - the text to append at the end of the File
charset - the charset used
Throws:
IOException

readLines

public static List readLines(Reader reader)
                      throws IOException
Reads the reader into a list of Strings for each line

Parameters:
reader - a Reader
Returns:
a List of lines
Throws:
IOException

eachFile

public static void eachFile(File self,
                            groovy.lang.Closure closure)
Invokes the closure for each file in the given directory

Parameters:
self - a File
closure - a closure

eachFileRecurse

public static void eachFileRecurse(File self,
                                   groovy.lang.Closure closure)
Invokes the closure for each file in the given directory and recursively. It is a depth-first exploration, directories are included in the search.

Parameters:
self - a File
closure - a closure

newReader

public static BufferedReader newReader(File file)
                                throws IOException
Helper method to create a buffered reader for a file

Parameters:
file - a File
Returns:
a BufferedReader
Throws:
IOException

newReader

public static BufferedReader newReader(File file,
                                       String charset)
                                throws FileNotFoundException,
                                       UnsupportedEncodingException
Helper method to create a buffered reader for a file, with a specified charset

Parameters:
file - a File
charset - the charset with which we want to write in the File
Returns:
a BufferedReader
Throws:
FileNotFoundException - if the File was not found
UnsupportedEncodingException - if the encoding specified is not supported

newReader

public static BufferedReader newReader(InputStream self)
Provides a reader for an arbitrary input stream

Parameters:
self - an input stream
Returns:
a reader

withReader

public static void withReader(File file,
                              groovy.lang.Closure closure)
                       throws IOException
Helper method to create a new BufferedReader for a file and then passes it into the closure and ensures its closed again afterwords

Parameters:
file -
Throws:
FileNotFoundException
IOException

newOutputStream

public static BufferedOutputStream newOutputStream(File file)
                                            throws IOException
Helper method to create a buffered output stream for a file

Parameters:
file -
Returns:
Throws:
FileNotFoundException
IOException

withOutputStream

public static void withOutputStream(File file,
                                    groovy.lang.Closure closure)
                             throws IOException
Helper method to create a new OutputStream for a file and then passes it into the closure and ensures its closed again afterwords

Parameters:
file - a File
Throws:
FileNotFoundException
IOException

withInputStream

public static void withInputStream(File file,
                                   groovy.lang.Closure closure)
                            throws IOException
Helper method to create a new InputStream for a file and then passes it into the closure and ensures its closed again afterwords

Parameters:
file - a File
Throws:
FileNotFoundException
IOException

newWriter

public static BufferedWriter newWriter(File file)
                                throws IOException
Helper method to create a buffered writer for a file

Parameters:
file - a File
Returns:
a BufferedWriter
Throws:
FileNotFoundException
IOException

newWriter

public static BufferedWriter newWriter(File file,
                                       boolean append)
                                throws IOException
Helper method to create a buffered writer for a file in append mode

Parameters:
file - a File
append - true if in append mode
Returns:
a BufferedWriter
Throws:
FileNotFoundException
IOException

newWriter

public static BufferedWriter newWriter(File file,
                                       String charset,
                                       boolean append)
                                throws IOException
Helper method to create a buffered writer for a file

Parameters:
file - a File
charset - the name of the encoding used to write in this file
append - true if in append mode
Returns:
a BufferedWriter
Throws:
FileNotFoundException
IOException

newWriter

public static BufferedWriter newWriter(File file,
                                       String charset)
                                throws IOException
Helper method to create a buffered writer for a file

Parameters:
file - a File
charset - the name of the encoding used to write in this file
Returns:
a BufferedWriter
Throws:
FileNotFoundException
IOException

withWriter

public static void withWriter(File file,
                              groovy.lang.Closure closure)
                       throws IOException
Helper method to create a new BufferedWriter for a file and then passes it into the closure and ensures it is closed again afterwords

Parameters:
file - a File
closure - a closure
Throws:
FileNotFoundException
IOException

withWriter

public static void withWriter(File file,
                              String charset,
                              groovy.lang.Closure closure)
                       throws IOException
Helper method to create a new BufferedWriter for a file in a specified encoding and then passes it into the closure and ensures it is closed again afterwords

Parameters:
file - a File
charset - the charset used
closure - a closure
Throws:
FileNotFoundException
IOException

withWriterAppend

public static void withWriterAppend(File file,
                                    String charset,
                                    groovy.lang.Closure closure)
                             throws IOException
Helper method to create a new BufferedWriter for a file in a specified encoding in append mode and then passes it into the closure and ensures it is closed again afterwords

Parameters:
file - a File
charset - the charset used
closure - a closure
Throws:
FileNotFoundException
IOException

newPrintWriter

public static PrintWriter newPrintWriter(File file)
                                  throws IOException
Helper method to create a new PrintWriter for a file

Parameters:
file - a File
Throws:
FileNotFoundException
IOException

newPrintWriter

public static PrintWriter newPrintWriter(File file,
                                         String charset)
                                  throws IOException
Helper method to create a new PrintWriter for a file with a specified charset

Parameters:
file - a File
charset - the charset
Returns:
a PrintWriter
Throws:
FileNotFoundException
IOException

withPrintWriter

public static void withPrintWriter(File file,
                                   groovy.lang.Closure closure)
                            throws IOException
Helper method to create a new PrintWriter for a file and then passes it into the closure and ensures its closed again afterwords

Parameters:
file - a File
Throws:
FileNotFoundException
IOException

withWriter

public static void withWriter(Writer writer,
                              groovy.lang.Closure closure)
                       throws IOException
Allows a writer to be used, calling the closure with the writer and then ensuring that the writer is closed down again irrespective of whether exceptions occur or the

Parameters:
writer - the writer which is used and then closed
closure - the closure that the writer is passed into
Throws:
IOException

withReader

public static void withReader(Reader writer,
                              groovy.lang.Closure closure)
                       throws IOException
Allows a Reader to be used, calling the closure with the writer and then ensuring that the writer is closed down again irrespective of whether exceptions occur or the

Parameters:
writer - the writer which is used and then closed
closure - the closure that the writer is passed into
Throws:
IOException

withStream

public static void withStream(InputStream stream,
                              groovy.lang.Closure closure)
                       throws IOException
Allows a InputStream to be used, calling the closure with the stream and then ensuring that the stream is closed down again irrespective of whether exceptions occur or the

Parameters:
stream - the stream which is used and then closed
closure - the closure that the stream is passed into
Throws:
IOException

readLines

public static List readLines(InputStream stream)
                      throws IOException
Reads the stream into a list of Strings for each line

Parameters:
stream - a stream
Returns:
a List of lines
Throws:
IOException

eachLine

public static void eachLine(InputStream stream,
                            groovy.lang.Closure closure)
                     throws IOException
Iterates through the given stream line by line

Parameters:
stream - a stream
closure - a closure
Throws:
IOException

eachLine

public static void eachLine(URL url,
                            groovy.lang.Closure closure)
                     throws IOException
Iterates through the lines read from the URL's associated input stream

Parameters:
url - a URL to open and read
closure - a closure to apply on each line
Throws:
IOException

withReader

public static void withReader(URL url,
                              groovy.lang.Closure closure)
                       throws IOException
Helper method to create a new BufferedReader for a URL and then passes it into the closure and ensures its closed again afterwords

Parameters:
url - a URL
Throws:
FileNotFoundException
IOException

withReader

public static void withReader(InputStream in,
                              groovy.lang.Closure closure)
                       throws IOException
Helper method to create a new BufferedReader for a stream and then passes it into the closure and ensures its closed again afterwords

Parameters:
in - a stream
Throws:
FileNotFoundException
IOException

withWriter

public static void withWriter(OutputStream stream,
                              groovy.lang.Closure closure)
                       throws IOException
Allows an output stream to be used, calling the closure with the output stream and then ensuring that the output stream is closed down again irrespective of whether exceptions occur

Parameters:
stream - the stream which is used and then closed
closure - the closure that the writer is passed into
Throws:
IOException

withWriter

public static void withWriter(OutputStream stream,
                              String charset,
                              groovy.lang.Closure closure)
                       throws IOException
Allows an output stream to be used, calling the closure with the output stream and then ensuring that the output stream is closed down again irrespective of whether exceptions occur.

Parameters:
stream - the stream which is used and then closed
charset - the charset used
closure - the closure that the writer is passed into
Throws:
IOException

withStream

public static void withStream(OutputStream stream,
                              groovy.lang.Closure closure)
                       throws IOException
Allows a OutputStream to be used, calling the closure with the stream and then ensuring that the stream is closed down again irrespective of whether exceptions occur.

Parameters:
stream - the stream which is used and then closed
closure - the closure that the stream is passed into
Throws:
IOException

newInputStream

public static BufferedInputStream newInputStream(File file)
                                          throws FileNotFoundException
Helper method to create a buffered input stream for a file

Parameters:
file - a File
Returns:
a BufferedInputStream of the file
Throws:
FileNotFoundException

eachByte

public static void eachByte(File self,
                            groovy.lang.Closure closure)
                     throws IOException
Traverse through each byte of the specified File

Parameters:
self - a File
closure - a closure
Throws:
IOException

eachByte

public static void eachByte(InputStream is,
                            groovy.lang.Closure closure)
                     throws IOException
Traverse through each byte of the specified stream

Parameters:
is - stream to iterate over
closure - closure to apply to each byte
Throws:
IOException

eachByte

public static void eachByte(URL url,
                            groovy.lang.Closure closure)
                     throws IOException
Traverse through each byte of the specified URL

Parameters:
url - url to iterate over
closure - closure to apply to each byte
Throws:
IOException

transformChar

public static void transformChar(Reader reader,
                                 Writer writer,
                                 groovy.lang.Closure closure)
Transforms the characters from a reader with a Closure and write them to a writer

Parameters:
reader -
writer -
closure -

transformLine

public static void transformLine(Reader reader,
                                 Writer writer,
                                 groovy.lang.Closure closure)
                          throws IOException
Transforms the lines from a reader with a Closure and write them to a writer

Parameters:
reader -
writer -
closure -
Throws:
IOException

filterLine

public static void filterLine(Reader reader,
                              Writer writer,
                              groovy.lang.Closure closure)
                       throws IOException
Filter the lines from a reader and write them on the writer, according to a closure which returns true or false.

Parameters:
reader - a reader
writer - a writer
closure - the closure which returns booleans
Throws:
IOException

filterLine

public static groovy.lang.Writable filterLine(File self,
                                              groovy.lang.Closure closure)
                                       throws IOException
Filters the lines of a File and creates a Writeable in return to stream the filtered lines

Parameters:
self - a File
closure - a closure which returns a boolean indicating to filter the line or not
Returns:
a Writable closure
Throws:
IOException - if self is not readable

filterLine

public static void filterLine(File self,
                              Writer writer,
                              groovy.lang.Closure closure)
                       throws IOException
Filter the lines from a File and write them on a writer, according to a closure which returns true or false

Parameters:
self - a File
writer - a writer
closure - a closure which returns a boolean value and takes a line as input
Throws:
IOException - if self is not readable

filterLine

public static groovy.lang.Writable filterLine(Reader reader,
                                              groovy.lang.Closure closure)
Filter the lines of a Reader and create a Writable in return to stream the filtered lines

Parameters:
reader - a reader
closure - a closure returning a boolean indicating to filter or not a line
Returns:
a Writable closure

filterLine

public static groovy.lang.Writable filterLine(InputStream self,
                                              groovy.lang.Closure predicate)
Filter lines from an input stream using a closure predicate

Parameters:
self - an input stream
predicate - a closure which returns boolean and takes a line
Returns:
a filtered writer

filterLine

public static void filterLine(InputStream self,
                              Writer writer,
                              groovy.lang.Closure predicate)
                       throws IOException
Filters lines from an input stream, writing to a writer, using a closure which returns boolean and takes a line.

Parameters:
self - an InputStream
writer - a writer to write output to
predicate - a closure which returns a boolean and takes a line as input
Throws:
IOException

readBytes

public static byte[] readBytes(File file)
                        throws IOException
Reads the content of the file into an array of byte

Parameters:
file - a File
Returns:
a List of Bytes
Throws:
IOException

withStreams

public static void withStreams(Socket socket,
                               groovy.lang.Closure closure)
                        throws IOException
Allows an InputStream and an OutputStream from a Socket to be used, calling the closure with the streams and then ensuring that the streams are closed down again irrespective of whether exceptions occur.

Parameters:
socket - a Socket
closure - a Closure
Throws:
IOException

leftShift

public static Writer leftShift(Socket self,
                               Object value)
                        throws IOException
Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket

Parameters:
self - a Socket
value - a value to append
Returns:
a Writer
Throws:
IOException

leftShift

public static OutputStream leftShift(Socket self,
                                     byte[] value)
                              throws IOException
Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket

Parameters:
self - a Socket
value - a value to append
Returns:
an OutputStream
Throws:
IOException

accept

public static Socket accept(ServerSocket serverSocket,
                            groovy.lang.Closure closure)
                     throws IOException
Allow to pass a Closure to the accept methods of ServerSocket

Parameters:
serverSocket - a ServerSocket
closure - a Closure
Returns:
a Socket
Throws:
IOException

asWritable

public static File asWritable(File file)
Parameters:
file - a File
Returns:
a File which wraps the input file and which implements Writable

asWritable

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

toList

public static List toList(String self)
Converts the given String into a List of strings of one character

Parameters:
self - a String
Returns:
a List of characters (a 1-character String)

getIn

public static InputStream getIn(Process self)
An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar way

Returns:
an InputStream

getText

public static String getText(Process self)
                      throws IOException
Read the text of the output stream of the Process.

Parameters:
self - a Process
Returns:
the text of the output
Throws:
IOException

getErr

public static InputStream getErr(Process self)
An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar way

Returns:
an InputStream

getOut

public static OutputStream getOut(Process self)
An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar way

Returns:
an OutputStream

leftShift

public static Writer leftShift(Process self,
                               Object value)
                        throws IOException
Overloads the left shift operator to provide an append mechanism to pipe into a Process

Parameters:
self - a Process
value - a value to append
Returns:
a Writer
Throws:
IOException

leftShift

public static OutputStream leftShift(Process self,
                                     byte[] value)
                              throws IOException
Overloads the left shift operator to provide an append mechanism to pipe into a Process

Parameters:
self - a Process
value - a value to append
Returns:
an OutputStream
Throws:
IOException

waitForOrKill

public static void waitForOrKill(Process self,
                                 long numberOfMillis)
Wait for the process to finish during a certain amount of time, otherwise stops the process.

Parameters:
self - a Process
numberOfMillis - the number of milliseconds to wait before stopping the process

eachMatch

public static void eachMatch(String str,
                             String regex,
                             groovy.lang.Closure closure)
process each regex matched substring of a string object. The object passed to the closure is a matcher with rich information of the last successful match

Parameters:
str - the target string
regex - a Regex string
closure - a closure

each

public static void each(Matcher matcher,
                        groovy.lang.Closure closure)

findIndexOf

public static int findIndexOf(Object self,
                              groovy.lang.Closure closure)
Iterates over every element of the collection and return the index of the first object that matches the condition specified in the closure

Parameters:
self - the iteration object over which we iterate
closure - the filter to perform a match on the collection
Returns:
an integer that is the index of the first macthed object.


Copyright © 2003-2004 The Codehaus. All Rights Reserved.