/** * Iterates through this file line by line, splitting each line using * the given regex separator. For each line, the given closure is called with * a single parameter being the list of strings computed by splitting the line * around matches of the given regular expression. * Finally the resources used for processing the file are closed. * * @param self a Path * @param regex the delimiting regular expression * @param charset opens the file with a specified charset * @param closure a closure * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @throws java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid * @see org.codehaus.groovy.runtime.IOGroovyMethods#splitEachLine(java.io.Reader, String, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T splitEachLine(Path self, String regex, String charset, @ClosureParams(value = FromString.class, options = {"List<String>", "String[]"}, conflictResolutionStrategy = PickFirstResolver.class) Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self, charset), regex, closure); }
/** * Reads the file into a list of Strings, with one item for each line. * * @param self a Path * @param charset opens the file with a specified charset * @return a List of lines * @throws java.io.IOException if an IOException occurs. * @see org.codehaus.groovy.runtime.IOGroovyMethods#readLines(java.io.Reader) * @since 2.3.0 */ public static List<String> readLines(Path self, String charset) throws IOException { return IOGroovyMethods.readLines(newReader(self, charset)); }
/** * Read the content of the Path and returns it as a String. * * @param self the file whose content we want to read * @return a String containing the content of the file * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static String getText(Path self) throws IOException { return IOGroovyMethods.getText(newReader(self)); }
/** * Reads the file into a list of Strings, with one item for each line. * * @param self a Path * @return a List of lines * @throws java.io.IOException if an IOException occurs. * @see org.codehaus.groovy.runtime.IOGroovyMethods#readLines(java.io.Reader) * @since 2.3.0 */ public static List<String> readLines(Path self) throws IOException { return IOGroovyMethods.readLines(newReader(self)); }
/** * Read the content of the Path using the specified encoding and return it * as a String. * * @param self the file whose content we want to read * @param charset the charset used to read the content of the file * @return a String containing the content of the file * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static String getText(Path self, String charset) throws IOException { return IOGroovyMethods.getText(newReader(self, charset)); }
/** * Filter the lines from this Path, and write them to the given writer based * on the given closure predicate. * * @param self a Path * @param writer a writer destination to write filtered lines to * @param closure a closure which takes each line as a parameter and returns * <code>true</code> if the line should be written to this writer. * @throws java.io.IOException if <code>self</code> is not readable * @see org.codehaus.groovy.runtime.IOGroovyMethods#filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure) * @since 2.3.0 */ public static void filterLine(Path self, Writer writer, @ClosureParams(value = SimpleType.class, options = "java.lang.String") Closure closure) throws IOException { IOGroovyMethods.filterLine(newReader(self), writer, closure); }
/** * Create a new BufferedReader for this file using the specified charset and then * passes it into the closure, ensuring the reader is closed after the * closure returns. The writer will use the given charset encoding, * but will not write a BOM. * * @param self a file object * @param charset the charset for this input stream * @param closure a closure * @return the value returned by the closure * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static <T> T withReader(Path self, String charset, @ClosureParams(value = SimpleType.class, options = "java.io.Reader") Closure<T> closure) throws IOException { return IOGroovyMethods.withReader(newReader(self, charset), closure); }
/** * Filter the lines from this Path, and write them to the given writer based * on the given closure predicate. * * @param self a Path * @param writer a writer destination to write filtered lines to * @param charset opens the file with a specified charset * @param closure a closure which takes each line as a parameter and returns * <code>true</code> if the line should be written to this writer. * @throws java.io.IOException if an IO error occurs * @see org.codehaus.groovy.runtime.IOGroovyMethods#filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure) * @since 2.3.0 */ public static void filterLine(Path self, Writer writer, String charset, @ClosureParams(value = SimpleType.class, options = "java.lang.String") Closure closure) throws IOException { IOGroovyMethods.filterLine(newReader(self, charset), writer, closure); }
/** * Create a new BufferedReader for this file and then * passes it into the closure, ensuring the reader is closed after the * closure returns. * * @param self a file object * @param closure a closure * @return the value returned by the closure * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static <T> T withReader(Path self, @ClosureParams(value = SimpleType.class, options = "java.io.Reader") Closure<T> closure) throws IOException { return IOGroovyMethods.withReader(newReader(self), closure); }
/** * Filters the lines of a Path and creates a Writable in return to * stream the filtered lines. * * @param self a Path * @param closure a closure which returns a boolean indicating to filter * the line or not * @return a Writable closure * @throws java.io.IOException if <code>self</code> is not readable * @see org.codehaus.groovy.runtime.IOGroovyMethods#filterLine(java.io.Reader, groovy.lang.Closure) * @since 2.3.0 */ public static Writable filterLine(Path self, @ClosureParams(value = SimpleType.class, options = "java.lang.String") Closure closure) throws IOException { return IOGroovyMethods.filterLine(newReader(self), closure); }
/** * Iterates through this file line by line. Each line is passed * to the given 1 or 2 arg closure. The file is read using a reader * which is closed before this method returns. * * @param self a Path * @param firstLine the line number value used for the first line (default is 1, set to 0 to start counting from 0) * @param closure a closure (arg 1 is line, optional arg 2 is line number) * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @see org.codehaus.groovy.runtime.IOGroovyMethods#eachLine(java.io.Reader, int, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T eachLine(Path self, int firstLine, @ClosureParams(value = FromString.class, options = {"String", "String,Integer"}) Closure<T> closure) throws IOException { return IOGroovyMethods.eachLine(newReader(self), firstLine, closure); }
/** * Iterates through this file line by line, splitting each line using * the given regex separator Pattern. For each line, the given closure is called with * a single parameter being the list of strings computed by splitting the line * around matches of the given regular expression. * Finally the resources used for processing the file are closed. * * @param self a Path * @param pattern the regular expression Pattern for the delimiter * @param charset opens the file with a specified charset * @param closure a closure * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @see org.codehaus.groovy.runtime.IOGroovyMethods#splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T splitEachLine(Path self, Pattern pattern, String charset, @ClosureParams(value=FromString.class,options={"List<String>","String[]"},conflictResolutionStrategy=PickFirstResolver.class) Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self, charset), pattern, closure); }
/** * Filters the lines of a Path and creates a Writable in return to * stream the filtered lines. * * @param self a Path * @param charset opens the file with a specified charset * @param closure a closure which returns a boolean indicating to filter * the line or not * @return a Writable closure * @throws java.io.IOException if an IOException occurs * @see org.codehaus.groovy.runtime.IOGroovyMethods#filterLine(java.io.Reader, groovy.lang.Closure) * @since 2.3.0 */ public static Writable filterLine(Path self, String charset, @ClosureParams(value = SimpleType.class, options = "java.lang.String") Closure closure) throws IOException { return IOGroovyMethods.filterLine(newReader(self, charset), closure); }
/** * Iterates through this file line by line. Each line is passed * to the given 1 or 2 arg closure. The file is read using a reader * which is closed before this method returns. * * @param self a Path * @param charset opens the file with a specified charset * @param firstLine the line number value used for the first line (default is 1, set to 0 to start counting from 0) * @param closure a closure (arg 1 is line, optional arg 2 is line number) * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @see org.codehaus.groovy.runtime.IOGroovyMethods#eachLine(java.io.Reader, int, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T eachLine(Path self, String charset, int firstLine, @ClosureParams(value = FromString.class, options = {"String", "String,Integer"}) Closure<T> closure) throws IOException { return IOGroovyMethods.eachLine(newReader(self, charset), firstLine, closure); }
/** * Iterates through this file line by line, splitting each line using * the given regex separator. For each line, the given closure is called with * a single parameter being the list of strings computed by splitting the line * around matches of the given regular expression. * Finally the resources used for processing the file are closed. * * @param self a Path * @param regex the delimiting regular expression * @param closure a closure * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @throws java.util.regex.PatternSyntaxException * if the regular expression's syntax is invalid * @see org.codehaus.groovy.runtime.IOGroovyMethods#splitEachLine(java.io.Reader, String, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T splitEachLine(Path self, String regex, @ClosureParams(value=FromString.class,options={"List<String>","String[]"},conflictResolutionStrategy=PickFirstResolver.class) Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self), regex, closure); }
/** * Iterates through this file line by line, splitting each line using * the given regex separator. For each line, the given closure is called with * a single parameter being the list of strings computed by splitting the line * around matches of the given regular expression. * Finally the resources used for processing the file are closed. * * @param self a Path * @param regex the delimiting regular expression * @param charset opens the file with a specified charset * @param closure a closure * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @throws java.util.regex.PatternSyntaxException * if the regular expression's syntax is invalid * @see org.codehaus.groovy.runtime.IOGroovyMethods#splitEachLine(java.io.Reader, String, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T splitEachLine(Path self, String regex, String charset, @ClosureParams(value=FromString.class,options={"List<String>","String[]"},conflictResolutionStrategy=PickFirstResolver.class) Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self, charset), regex, closure); }
/** * Iterates through this file line by line, splitting each line using * the given separator Pattern. For each line, the given closure is called with * a single parameter being the list of strings computed by splitting the line * around matches of the given regular expression Pattern. * Finally the resources used for processing the file are closed. * * @param self a Path * @param pattern the regular expression Pattern for the delimiter * @param closure a closure * @return the last value returned by the closure * @throws java.io.IOException if an IOException occurs. * @see org.codehaus.groovy.runtime.IOGroovyMethods#splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure) * @since 2.3.0 */ public static <T> T splitEachLine(Path self, Pattern pattern, @ClosureParams(value=FromString.class,options={"List<String>","String[]"},conflictResolutionStrategy=PickFirstResolver.class) Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self), pattern, closure); }