de.caff.util

## Class IOUtil

- java.lang.Object
- - de.caff.util.IOUtil

-     public class IOUtil
      extends java.lang.Object

  Helpers for i/o.
  Since:
    January 15, 2019
  Author:
    Rammi

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `discardInput(java.io.InputStream is)` Read all input from the given stream without using it.
    `static byte[]` | `readAllBytes(java.io.InputStream is)` Read all bytes from an input stream.
    `static java.lang.String` | `readAllText(java.io.InputStream is)` Read all text from a stream, using the default charset.
    `static java.lang.String` | `readAllText(java.io.InputStream is, java.nio.charset.Charset charset)` Read all text from a stream.
    `static java.lang.String` | `readAllTextUtf8(java.io.InputStream is)` Read all text from a stream, using UTF-8 encoding.
    `static void` | `readFully(java.io.InputStream is, byte[] data)` Read a number of bytes.
    `static void` | `readFully(java.io.InputStream is, byte[] data, int length)` Read a number of bytes.
    `static void` | `readFully(java.io.InputStream is, byte[] data, int offset, int length)` Read a number of bytes.

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

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

- - ### Method Detail

    - #### readFully

          public static void readFully(@NotNull
                                       java.io.InputStream is,
                                       @NotNull
                                       byte[] data,
                                       int offset,
                                       int length)
                                throws java.io.IOException

      Read a number of bytes.
      Parameters:
        `is` - input stream to read from
        `data` - byte array for collecting the input (must provide enough space)
        `offset` - offset into the byte array where byte collection starts (has to be non-negative)
        `length` - number of bytes to read (has to non-negative)
      Throws:
        `java.io.IOException` - on read errors
        `java.io.EOFException` - if there are not at least `length` bytes in the stream available

    - #### readFully

          public static void readFully(@NotNull
                                       java.io.InputStream is,
                                       @NotNull
                                       byte[] data,
                                       int length)
                                throws java.io.IOException

      Read a number of bytes. This starts reading at offset `0`.
      Parameters:
        `is` - input stream to read from
        `data` - byte array for collecting the input (must provide enough space)
        `length` - number of bytes to read (has to non-negative)
      Throws:
        `java.io.IOException` - on read errors
        `java.io.EOFException` - if there are not at least `length` bytes in the stream available

    - #### readFully

          public static void readFully(@NotNull
                                       java.io.InputStream is,
                                       @NotNull
                                       byte[] data)
                                throws java.io.IOException

      Read a number of bytes. This starts reading at offset `0` and reads until the byte array is filled.
      Parameters:
        `is` - input stream to read from
        `data` - byte array for collecting the input (must provide enough space)
      Throws:
        `java.io.IOException` - on read errors
        `java.io.EOFException` - if there are not at least `length` bytes in the stream available

    - #### readAllBytes

          @NotNull
          public static byte[] readAllBytes(@NotNull
                                                     java.io.InputStream is)
                                              throws java.io.IOException

      Read all bytes from an input stream.
      Parameters:
        `is` - input stream
      Returns:
        bytes read
      Throws:
        `java.io.IOException` - on read errors

    - #### readAllText

          @NotNull
          public static java.lang.String readAllText(@NotNull
                                                              java.io.InputStream is,
                                                              @NotNull
                                                              java.nio.charset.Charset charset)
                                                       throws java.io.IOException

      Read all text from a stream.
      Parameters:
        `is` - stream to read from
        `charset` - charset to use for byte to text conversion
      Returns:
        text read
      Throws:
        `java.io.IOException` - on read errors

    - #### readAllText

          @NotNull
          public static java.lang.String readAllText(@NotNull
                                                              java.io.InputStream is)
                                                       throws java.io.IOException

      Read all text from a stream, using the default charset.
      Parameters:
        `is` - stream to read from
      Returns:
        text read
      Throws:
        `java.io.IOException` - on read errors
      See Also:
        `Charset.defaultCharset()`

    - #### readAllTextUtf8

          @NotNull
          public static java.lang.String readAllTextUtf8(@NotNull
                                                                  java.io.InputStream is)
                                                           throws java.io.IOException

      Read all text from a stream, using UTF-8 encoding.
      Parameters:
        `is` - stream to read from
      Returns:
        text read
      Throws:
        `java.io.IOException` - on read errors
      See Also:
        `Charset.defaultCharset()`

    - #### discardInput

          public static void discardInput(@NotNull
                                          java.io.InputStream is)
                                   throws java.io.IOException

      Read all input from the given stream without using it.
      Parameters:
        `is` - input stream
      Throws:
        `java.io.IOException` - if reading runs into an exception other than `EOFException`