Package: java.io

## [Java] Class OutputStream

- java.io.OutputStream

-     public class OutputStream
      extends Object

  GDK enhancements for OutputStream.

  displayName:
    OutputStream
  receiverFqcn:
    java.io.OutputStream

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Writer` | `leftShift(Object value)`
    `` | `public OutputStream` | `leftShift(InputStream in)` Pipe an InputStream into an OutputStream for efficient stream copying.
    `` | `public OutputStream` | `leftShift(byte[] value)` Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.
    `` | `public ObjectOutputStream` | `newObjectOutputStream()` Create an object output stream for this output stream.
    `` | `public PrintWriter` | `newPrintWriter()` Create a new PrintWriter for this OutputStream.
    `` | `public Writer` | `newWriter()` Creates a writer for this stream.
    `` | `public Writer` | `newWriter(String charset)` Creates a writer for this stream using the given charset.
    `` | `public void` | `setBytes(byte[] bytes)` Write the byte[] to the output stream.
    `<T>` | `public T` | `withObjectOutputStream(Closure<T> closure)` Create a new ObjectOutputStream for this output stream and then pass it to the closure.
    `<T>` | `public T` | `withPrintWriter(Closure<T> closure)` Create a new PrintWriter for this OutputStream.
    `<T>` | `public T` | `withWriter(Closure<T> closure)` Creates a writer from this stream, passing it to the given closure.
    `<T>` | `public T` | `withWriter(String charset, Closure<T> closure)` Creates a writer from this stream, passing it to the given closure.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `addShutdownHook, any, any, asBoolean, asType, clamp, clamp, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, takeIf, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits`

- - ### Method Detail

    - #### public Writer leftShift(Object value)

    - #### public OutputStream leftShift(InputStream in)

      Pipe an InputStream into an OutputStream for efficient stream copying.

      throws:
        IOException if an I/O error occurs.
      Parameters:
        `in` - stream to read from
      Returns:
        the outputstream itself
      Since:
        1.0

    - #### public OutputStream leftShift(byte[] value)

      Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.

      throws:
        IOException if an I/O error occurs.
      Parameters:
        `value` - a value to append
      Returns:
        an OutputStream
      Since:
        1.0

    - #### public ObjectOutputStream newObjectOutputStream()

      Create an object output stream for this output stream.

      throws:
        IOException if an IOException occurs.
      Returns:
        an object output stream
      Since:
        1.5.0

    - #### public PrintWriter newPrintWriter()

      Create a new PrintWriter for this OutputStream.

      Returns:
        a PrintWriter
      Since:
        2.2.0

    - #### public Writer newWriter()

      Creates a writer for this stream.

      Returns:
        the newly created Writer
      Since:
        2.2.0

    - #### public Writer newWriter(String charset)

      Creates a writer for this stream using the given charset.

      throws:
        UnsupportedEncodingException if an encoding exception occurs.
      Parameters:
        `charset` - the charset used
      Returns:
        the newly created Writer
      Since:
        2.2.0

    - #### public void setBytes(byte[] bytes)

      Write the byte[] to the output stream. The stream is closed before this method returns.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `bytes` - the byte[] to write to the output stream
      Since:
        1.7.1

    - #### <T> public T withObjectOutputStream(Closure<T> closure)

      Create a new ObjectOutputStream for this output stream and then pass it to the closure. This method ensures the stream is closed after the closure returns.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        withStream(java.io.OutputStream, groovy.lang.Closure)
      Since:
        1.5.0

    - #### <T> public T withPrintWriter(Closure<T> closure)

      Create a new PrintWriter for this OutputStream. The writer is passed to the closure, and will be closed before this method returns.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `closure` - the closure to invoke with the PrintWriter
      Returns:
        the value returned by the closure
      Since:
        2.2.0

    - #### <T> public T withWriter(Closure<T> closure)

      Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `closure` - the closure that the writer is passed into
      Returns:
        the value returned by the closure
      See Also:
        withWriter(java.io.Writer, groovy.lang.Closure)
      Since:
        1.5.2

    - #### <T> public T withWriter(String charset, Closure<T> closure)

      Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `charset` - the charset used
        `closure` - the closure that the writer is passed into
      Returns:
        the value returned by the closure
      See Also:
        withWriter(java.io.Writer, groovy.lang.Closure)
      Since:
        1.5.2