Class Streams

java.lang.Object
de.espirit.common.tools.Streams

public final class Streams extends Object
Generic utility to provide stream related operations.
Since:
5.2.21
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    close(@Nullable Closeable... closables)
    Closes the provided closables and swallows any IOExceptions and RuntimeExceptions.
    static @NotNull String
    toBase64(@org.jetbrains.annotations.NotNull byte[] bytes)
    Encodes a raw byte array into a BASE64 string representation in accordance with RFC 2045.
    static @org.jetbrains.annotations.NotNull byte[]
    toByteArray(@NotNull InputStream in)
    Read the content of an input stream into a byte array.
    static @NotNull String
    toString(@NotNull InputStream in, @NotNull String encoding)
    Read the content of the specified input stream and returns the content as string using the specified encoding.
    static long
    write(@NotNull InputStream in, @NotNull OutputStream out)
    Transfers all date from the given input stream to the given output stream and returns the number of transfered bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Streams

      public Streams()
  • Method Details

    • toByteArray

      @NotNull public static @org.jetbrains.annotations.NotNull byte[] toByteArray(@NotNull @NotNull InputStream in) throws IOException
      Read the content of an input stream into a byte array. The stream will be closed after processing.
      Parameters:
      in - The input stream to read from.
      Returns:
      A byte array containing the content of the provided input stream.
      Throws:
      IOException - If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
      Since:
      5.2.21
    • toString

      @NotNull public static @NotNull String toString(@NotNull @NotNull InputStream in, @NotNull @NotNull String encoding) throws IOException
      Read the content of the specified input stream and returns the content as string using the specified encoding. The stream will be closed after processing.
      Parameters:
      in - The input stream to read from.
      encoding - The encoding to use for the string interpretation.
      Returns:
      The stream content as string.
      Throws:
      IOException - If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
      Since:
      5.2.21
    • toBase64

      @NotNull public static @NotNull String toBase64(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes)
      Encodes a raw byte array into a BASE64 string representation in accordance with RFC 2045.
      Parameters:
      bytes - The bytes to convert. If length 0, "" will be returned.
      Returns:
      A BASE64 encoded string.
      Since:
      5.2.21
    • write

      public static long write(@NotNull @NotNull InputStream in, @NotNull @NotNull OutputStream out) throws IOException
      Transfers all date from the given input stream to the given output stream and returns the number of transfered bytes. Both input and output stream will be closed when this call returns.
      Parameters:
      in - The input stream to read from.
      out - The ouput stream to write to.
      Returns:
      The number of transfered bytes.
      Throws:
      IOException
      Since:
      5.2.21
    • close

      public static void close(@Nullable @Nullable Closeable... closables)
      Closes the provided closables and swallows any IOExceptions and RuntimeExceptions.
      Parameters:
      closables - the instances to close - null-values are ignored
      Since:
      5.2.21