Interface GeneratedFile


public interface GeneratedFile
A common interface to allow referencing a generated file in either Groovy or Java.
Since:
1.0
Author:
graemerocher
  • Method Details

    • toURI

      URI toURI()
      The URI to write to.
      Returns:
      The URI
    • getName

      String getName()
      Returns:
      The name of the file
    • openInputStream

      InputStream openInputStream() throws IOException
      Gets an InputStream for this file object.
      Returns:
      an InputStream
      Throws:
      IllegalStateException - if this file object was opened for writing and does not support reading
      UnsupportedOperationException - if this kind of file object does not support byte access
      IOException - if an I/O error occurred
    • openOutputStream

      OutputStream openOutputStream() throws IOException
      Gets an OutputStream for this file object.
      Returns:
      an OutputStream
      Throws:
      IllegalStateException - if this file object was opened for reading and does not support writing
      UnsupportedOperationException - if this kind of file object does not support byte access
      IOException - if an I/O error occurred
    • openReader

      Reader openReader() throws IOException
      Gets a reader for this object. The returned reader will replace bytes that cannot be decoded with the default translation character. In addition, the reader may report a diagnostic unless ignoreEncodingErrors is true.
      Returns:
      a Reader
      Throws:
      IllegalStateException - if this file object was opened for writing and does not support reading
      UnsupportedOperationException - if this kind of file object does not support character access
      IOException - if an I/O error occurred
    • getTextContent

      CharSequence getTextContent() throws IOException
      Gets the character content of this file object, if available. Any byte that cannot be decoded will be replaced by the default translation character. In addition, a diagnostic may be reported unless ignoreEncodingErrors is true.
      Returns:
      a CharSequence if available; null otherwise
      Throws:
      IllegalStateException - if this file object was opened for writing and does not support reading
      UnsupportedOperationException - if this kind of file object does not support character access
      IOException - if an I/O error occurred
    • openWriter

      Writer openWriter() throws IOException
      Gets a Writer for this file object.
      Returns:
      a Writer
      Throws:
      IllegalStateException - if this file object was opened for reading and does not support writing
      UnsupportedOperationException - if this kind of file object does not support character access
      IOException - if an I/O error occurred
    • write

      default void write(GeneratedFile.ThrowingConsumer<? super Writer> consumer) throws IOException
      Writes the context to the file.
      Parameters:
      consumer - the code generating block
      Throws:
      IOException - in case of I/O error
      Since:
      4.2.0