Class WritableFile

java.lang.Object
java.io.File
org.codehaus.groovy.runtime.WritableFile
All Implemented Interfaces:
Writable, Serializable, Comparable<File>

public class WritableFile extends File implements Writable
A file wrapper implementing the Writable interface to support writing file contents. Allows a file to be written to any output stream, optionally with a specified character encoding.
See Also:
  • Constructor Details

    • WritableFile

      public WritableFile(File delegate)
      Constructs a WritableFile from a delegate File with default character encoding.
      Parameters:
      delegate - the underlying File to wrap
    • WritableFile

      public WritableFile(File delegate, String encoding)
      Constructs a WritableFile from a delegate File with optional character encoding.
      Parameters:
      delegate - the underlying File to wrap
      encoding - the character encoding to use when reading the file, or null for default
  • Method Details

    • writeTo

      public Writer writeTo(Writer out) throws IOException
      Writes this file's contents to the specified Writer. If encoding was specified, uses that encoding when reading the file.
      Specified by:
      writeTo in interface Writable
      Parameters:
      out - the Writer to write the file contents to
      Returns:
      the same Writer for method chaining
      Throws:
      IOException - if an I/O error occurs during reading or writing