Package groovy.io

# Class GroovyPrintWriter

java.lang.Object
java.io.Writer
java.io.PrintWriter
groovy.io.GroovyPrintWriter

All Implemented Interfaces:
  `Closeable`, `Flushable`, `Appendable`, `AutoCloseable`

public class GroovyPrintWriter extends PrintWriter
A PrintWriter that outputs objects in Groovy style. That means print(Object) uses InvokerHelper.toString(Object) to produce the same results as Writer.print(Object).

Since:
  1.6

- ## Field Summary

  ### Fields inherited from class java.io.PrintWriter

  `out`

  ### Fields inherited from class java.io.Writer

  `lock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GroovyPrintWriter(File file)`
  Creates a writer for the supplied file.
  `GroovyPrintWriter(File file, String csn)`
  Creates a writer for the supplied file using the given charset name.
  `GroovyPrintWriter(OutputStream out)`
  Creates a writer for the supplied output stream.
  `GroovyPrintWriter(OutputStream out, boolean autoflush)`
  Creates a writer for the supplied output stream.
  `GroovyPrintWriter(Writer out)`
  Creates a writer that delegates to the supplied writer.
  `GroovyPrintWriter(Writer out, boolean autoflush)`
  Creates a writer that delegates to the supplied writer.
  `GroovyPrintWriter(String filename)`
  Creates a writer for the supplied file name.
  `GroovyPrintWriter(String filename, String csn)`
  Creates a writer for the supplied file name using the given charset name.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `print(Object x)`
  Prints an object using Groovy formatting.
  `void`
  `println(Object x)`
  Prints an object followed by a line separator using Groovy formatting.

  ### Methods inherited from class java.io.PrintWriter

  `append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write`

  ### Methods inherited from class java.io.Writer

  `nullWriter`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### GroovyPrintWriter

    public GroovyPrintWriter(File file) throws FileNotFoundException
    Creates a writer for the supplied file.
    Parameters:
      `file` - the target file
    Throws:
      `FileNotFoundException` - if the file cannot be opened

  - ### GroovyPrintWriter

    public GroovyPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException
    Creates a writer for the supplied file using the given charset name.
    Parameters:
      `file` - the target file
      `csn` - the charset name
    Throws:
      `FileNotFoundException` - if the file cannot be opened
      `UnsupportedEncodingException` - if the charset is unsupported

  - ### GroovyPrintWriter

    public GroovyPrintWriter(Writer out)
    Creates a writer that delegates to the supplied writer.
    Parameters:
      `out` - the underlying writer

  - ### GroovyPrintWriter

    public GroovyPrintWriter(Writer out, boolean autoflush)
    Creates a writer that delegates to the supplied writer.
    Parameters:
      `out` - the underlying writer
      `autoflush` - whether println operations flush automatically

  - ### GroovyPrintWriter

    public GroovyPrintWriter(OutputStream out)
    Creates a writer for the supplied output stream.
    Parameters:
      `out` - the underlying output stream

  - ### GroovyPrintWriter

    public GroovyPrintWriter(OutputStream out, boolean autoflush)
    Creates a writer for the supplied output stream.
    Parameters:
      `out` - the underlying output stream
      `autoflush` - whether println operations flush automatically

  - ### GroovyPrintWriter

    public GroovyPrintWriter(String filename) throws FileNotFoundException
    Creates a writer for the supplied file name.
    Parameters:
      `filename` - the target file name
    Throws:
      `FileNotFoundException` - if the file cannot be opened

  - ### GroovyPrintWriter

    public GroovyPrintWriter(String filename, String csn) throws FileNotFoundException, UnsupportedEncodingException
    Creates a writer for the supplied file name using the given charset name.
    Parameters:
      `filename` - the target file name
      `csn` - the charset name
    Throws:
      `FileNotFoundException` - if the file cannot be opened
      `UnsupportedEncodingException` - if the charset is unsupported

- ## Method Details

  - ### print

    public void print(Object x)
    Prints an object using Groovy formatting.
    Overrides:
      `print` in class `PrintWriter`
    Parameters:
      `x` - the value to print

  - ### println

    public void println(Object x)
    Prints an object followed by a line separator using Groovy formatting.
    Overrides:
      `println` in class `PrintWriter`
    Parameters:
      `x` - the value to print