org.apache.commons.io.output

## Class ProxyCollectionWriter

- java.lang.Object
- - java.io.Writer
  - - org.apache.commons.io.output.FilterCollectionWriter
    - - org.apache.commons.io.output.ProxyCollectionWriter

- All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable
  Direct Known Subclasses:
    TeeWriter

      public class ProxyCollectionWriter
      extends FilterCollectionWriter

  A Proxy stream collection which acts as expected, that is it passes the method calls on to the proxied streams and doesn't change which methods are being called. It is an alternative base class to `FilterWriter` and `FilterCollectionWriter` to increase reusability, because FilterWriter changes the methods being called, such as `write(char[])` to `write(char[], int, int)` and `write(String)` to `write(String, int, int)`. This is in contrast to `ProxyWriter` which is backed by a single `Writer`.
  Since:
    2.7

- - ### Field Summary

    - ### Fields inherited from class org.apache.commons.io.output.FilterCollectionWriter

      `EMPTY_WRITERS, writers`

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

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProxyCollectionWriter(Collection<Writer> writers)` Creates a new proxy collection writer.
    `ProxyCollectionWriter(Writer... writers)` Creates a new proxy collection writer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `afterWrite(int n)` Invoked by the write methods after the proxied call has returned successfully.
    `Writer` | `append(char c)` Invokes the delegates' `append(char)` methods.
    `Writer` | `append(CharSequence csq)` Invokes the delegates' `append(CharSequence)` methods.
    `Writer` | `append(CharSequence csq, int start, int end)` Invokes the delegates' `append(CharSequence, int, int)` methods.
    `protected void` | `beforeWrite(int n)` Invoked by the write methods before the call is proxied.
    `void` | `close()` Invokes the delegate's `close()` method.
    `void` | `flush()` Invokes the delegate's `flush()` method.
    `protected void` | `handleIOException(IOException e)` Handle any IOExceptions thrown.
    `void` | `write(char[] cbuf)` Invokes the delegate's `write(char[])` method.
    `void` | `write(char[] cbuf, int off, int len)` Invokes the delegate's `write(char[], int, int)` method.
    `void` | `write(int c)` Invokes the delegate's `write(int)` method.
    `void` | `write(String str)` Invokes the delegate's `write(String)` method.
    `void` | `write(String str, int off, int len)` Invokes the delegate's `write(String)` method.

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

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

- - ### Constructor Detail

    - #### ProxyCollectionWriter

          public ProxyCollectionWriter(Collection<Writer> writers)

      Creates a new proxy collection writer.
      Parameters:
        `writers` - Writers object to provide the underlying targets.

    - #### ProxyCollectionWriter

          public ProxyCollectionWriter(Writer... writers)

      Creates a new proxy collection writer.
      Parameters:
        `writers` - Writers to provide the underlying targets.

  - ### Method Detail

    - #### afterWrite

          protected void afterWrite(int n)
                             throws IOException

      Invoked by the write methods after the proxied call has returned successfully. The number of chars written (1 for the `write(int)` method, buffer length for `write(char[])`, etc.) is given as an argument.

      Subclasses can override this method to add common post-processing functionality without having to override all the write methods. The default implementation does nothing.

      Parameters:
        `n` - number of chars written
      Throws:
        `IOException` - if the post-processing fails

    - #### append

          public Writer append(char c)
                        throws IOException

      Invokes the delegates' `append(char)` methods.
      Specified by:
        `append` in interface `Appendable`
      Overrides:
        `append` in class `FilterCollectionWriter`
      Parameters:
        `c` - The character to write
      Returns:
        this writer
      Throws:
        `IOException` - if an I/O error occurs.
      Since:
        2.0

    - #### append

          public Writer append(CharSequence csq)
                        throws IOException

      Invokes the delegates' `append(CharSequence)` methods.
      Specified by:
        `append` in interface `Appendable`
      Overrides:
        `append` in class `FilterCollectionWriter`
      Parameters:
        `csq` - The character sequence to write
      Returns:
        this writer
      Throws:
        `IOException` - if an I/O error occurs.

    - #### append

          public Writer append(CharSequence csq,
                               int start,
                               int end)
                        throws IOException

      Invokes the delegates' `append(CharSequence, int, int)` methods.
      Specified by:
        `append` in interface `Appendable`
      Overrides:
        `append` in class `FilterCollectionWriter`
      Parameters:
        `csq` - The character sequence to write
        `start` - The index of the first character to write
        `end` - The index of the first character to write (exclusive)
      Returns:
        this writer
      Throws:
        `IOException` - if an I/O error occurs.

    - #### beforeWrite

          protected void beforeWrite(int n)
                              throws IOException

      Invoked by the write methods before the call is proxied. The number of chars to be written (1 for the `write(int)` method, buffer length for `write(char[])`, etc.) is given as an argument.

      Subclasses can override this method to add common pre-processing functionality without having to override all the write methods. The default implementation does nothing.

      Parameters:
        `n` - number of chars to be written
      Throws:
        `IOException` - if the pre-processing fails

    - #### close

          public void close()
                     throws IOException

      Invokes the delegate's `close()` method.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `FilterCollectionWriter`
      Throws:
        `IOException` - if an I/O error occurs.

    - #### flush

          public void flush()
                     throws IOException

      Invokes the delegate's `flush()` method.
      Specified by:
        `flush` in interface `Flushable`
      Overrides:
        `flush` in class `FilterCollectionWriter`
      Throws:
        `IOException` - if an I/O error occurs.

    - #### handleIOException

          protected void handleIOException(IOException e)
                                    throws IOException

      Handle any IOExceptions thrown.

      This method provides a point to implement custom exception handling. The default behavior is to re-throw the exception.

      Parameters:
        `e` - The IOException thrown
      Throws:
        `IOException` - if an I/O error occurs.

    - #### write

          public void write(char[] cbuf)
                     throws IOException

      Invokes the delegate's `write(char[])` method.
      Overrides:
        `write` in class `FilterCollectionWriter`
      Parameters:
        `cbuf` - the characters to write
      Throws:
        `IOException` - if an I/O error occurs.

    - #### write

          public void write(char[] cbuf,
                            int off,
                            int len)
                     throws IOException

      Invokes the delegate's `write(char[], int, int)` method.
      Overrides:
        `write` in class `FilterCollectionWriter`
      Parameters:
        `cbuf` - the characters to write
        `off` - The start offset
        `len` - The number of characters to write
      Throws:
        `IOException` - if an I/O error occurs.

    - #### write

          public void write(int c)
                     throws IOException

      Invokes the delegate's `write(int)` method.
      Overrides:
        `write` in class `FilterCollectionWriter`
      Parameters:
        `c` - the character to write
      Throws:
        `IOException` - if an I/O error occurs.

    - #### write

          public void write(String str)
                     throws IOException

      Invokes the delegate's `write(String)` method.
      Overrides:
        `write` in class `FilterCollectionWriter`
      Parameters:
        `str` - the string to write
      Throws:
        `IOException` - if an I/O error occurs.

    - #### write

          public void write(String str,
                            int off,
                            int len)
                     throws IOException

      Invokes the delegate's `write(String)` method.
      Overrides:
        `write` in class `FilterCollectionWriter`
      Parameters:
        `str` - the string to write
        `off` - The start offset
        `len` - The number of characters to write
      Throws:
        `IOException` - if an I/O error occurs.

Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.