de.caff.io

## Class OutputStreamStringCollector

- java.lang.Object
- - de.caff.io.OutputStreamStringCollector

- All Implemented Interfaces:
    StringCollector, java.lang.AutoCloseable

      public class OutputStreamStringCollector
      extends java.lang.Object
      implements java.lang.AutoCloseable, StringCollector

  String collector which writes all collected strings to an output stream.

  Usually should be closed after usage. Recommend is to use it in try-with-resources-

  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.nio.charset.Charset` | `DEFAULT_CHARSET` The default charset (UTF_8).

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutputStreamStringCollector(java.io.OutputStream stream)` Constructor.
    `OutputStreamStringCollector(java.io.OutputStream stream, java.nio.charset.Charset charset)` Constructor.
    `OutputStreamStringCollector(java.io.OutputStream stream, java.lang.String charsetName)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(char ch)` Add a character to this collector.
    `void` | `add(java.lang.String str)` Add a string t this collector.
    `void` | `close()` Closes this stream and releases any system resources associated with it.
    `java.io.IOException` | `getError()` Get a possible error.
    `char` | `getLastLetter()` Get the last letter of the last string which was added.
    `void` | `rethrow()` Rethrow an error which was caught during writing of added strings.

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

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

- - ### Field Detail

    - #### DEFAULT_CHARSET

          public static final java.nio.charset.Charset DEFAULT_CHARSET

      The default charset (UTF_8).

  - ### Constructor Detail

    - #### OutputStreamStringCollector

          public OutputStreamStringCollector(@NotNull
                                             java.io.OutputStream stream)

      Constructor. This will use the `DEFAULT_CHARSET` for output encoding.
      Parameters:
        `stream` - output stream

    - #### OutputStreamStringCollector

          public OutputStreamStringCollector(@NotNull
                                             java.io.OutputStream stream,
                                             @NotNull
                                             java.lang.String charsetName)

      Constructor.
      Parameters:
        `stream` - output stream
        `charsetName` - name of charset to use for output encoding

    - #### OutputStreamStringCollector

          public OutputStreamStringCollector(@NotNull
                                             java.io.OutputStream stream,
                                             @NotNull
                                             java.nio.charset.Charset charset)

      Constructor.
      Parameters:
        `stream` - output stream
        `charset` - charset used for string output encoding

  - ### Method Detail

    - #### add

          public void add(@NotNull
                          java.lang.String str)

      Add a string t this collector.
      Specified by:
        `add` in interface `StringCollector`
      Parameters:
        `str` - string collector

    - #### add

          public void add(char ch)

      Add a character to this collector.
      Specified by:
        `add` in interface `StringCollector`
      Parameters:
        `ch` - character to add

    - #### getLastLetter

          public char getLastLetter()

      Get the last letter of the last string which was added.
      Specified by:
        `getLastLetter` in interface `StringCollector`
      Returns:
        last letter, zero at the very beginning

    - #### close

          public void close()
                     throws java.io.IOException

      Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Throws:
        `java.io.IOException` - if an I/O error occurs

    - #### rethrow

          public void rethrow()
                       throws java.io.IOException

      Rethrow an error which was caught during writing of added strings. Does nothing if no error happened.
      Throws:
        `java.io.IOException` - exception caught during writing strings

    - #### getError

          @Nullable
          public java.io.IOException getError()

      Get a possible error.
      Returns:
        error caught during string writing