de.caff.io

## Class InputStreamPipe

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

- All Implemented Interfaces:
    java.lang.Runnable

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

  A pipe which reads data from am input stream and pipes it to an output stream.

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

  See also `InputStreamBuffer` which collects the output in a ring buffer, or `InputStreamSink` which discards all bytes read.

  Since:
    August 10, 2022
  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InputStreamPipe(java.io.InputStream is, java.io.OutputStream os)` 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 InputStreamPipe` | `startOn(java.io.InputStream inStream, java.io.OutputStream outStream)` Start a pipe on the given stream.

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

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

- - ### Constructor Detail

    - #### InputStreamPipe

          public InputStreamPipe(@NotNull
                                 java.io.InputStream is,
                                 @NotNull
                                 java.io.OutputStream os)

      Constructor.
      Parameters:
        `is` - input stream
        `os` - output 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 InputStreamPipe startOn(@NotNull
                                                         java.io.InputStream inStream,
                                                         @NotNull
                                                         java.io.OutputStream outStream)

      Start a pipe on the given stream.
      Parameters:
        `inStream` - input stream
        `outStream` - output stream
      Returns:
        input stream pipe