de.caff.io

## Class InputStreamSink

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

- All Implemented Interfaces:
    java.lang.Runnable

      public class InputStreamSink
      extends java.lang.Object
      implements java.lang.Runnable

  A sink for data from an input stream which discards the incoming data.

  It is especially useful for handling the outputting streams of `Process`. Create via `startOn(InputStream)` which will automatically discard all bytes from the stream in a background thread.

  See also `InputStreamBuffer` which collects the output in a ring buffer, and `InputStreamPipe` which forwards all bytes from one stream to another.

  Since:
    August 10, 2022
  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InputStreamSink(java.io.InputStream is)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.io.IOException` | `getError()` Return a possible error which happened during reading the stream when using the `run()` method.
    `long` | `getTotalByteCount()` Get the total number of bytes read by this sink.
    `void` | `run()` When an object implementing interface `Runnable` is used to create a thread, starting the thread causes the object's `run` method to be called in that separately executing thread.
    `static InputStreamSink` | `startOn(java.io.InputStream inStream)` Start a sink on the given stream.

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

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

- - ### Constructor Detail

    - #### InputStreamSink

          public InputStreamSink(@NotNull
                                 java.io.InputStream is)

      Constructor. Note that in most use cases the factory method `startOn(InputStream)` is a better way to create an input stream sink.
      Parameters:
        `is` - input stream

  - ### Method Detail

    - #### getTotalByteCount

          public long getTotalByteCount()

      Get the total number of bytes read by this sink.
      Returns:
        total number of bytes read so far

    - #### getError

          @Nullable
          public java.io.IOException getError()

      Return a possible error which happened during reading the stream when using the `run()` method.
      Returns:
        error caught during run() or `null`, if no error was caught

    - #### run

          public void run()

      When an object implementing interface `Runnable` is used to create a thread, starting the thread causes the object's `run` method to be called in that separately executing thread.

      The general contract of the method `run` is that it may take any action whatsoever.

      Specified by:
        `run` in interface `java.lang.Runnable`
      See Also:
        `Thread.run()`

    - #### startOn

          @NotNull
          public static InputStreamSink startOn(@NotNull
                                                         java.io.InputStream inStream)

      Start a sink on the given stream.
      Parameters:
        `inStream` - input stream
      Returns:
        input stream sink based on the given stream