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 Details

    • Streams

      public Streams()
  • Method Details

    • toByteArray

      @NotNull public static byte[] toByteArray(@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 String toString(@NotNull InputStream in, @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 String toBase64(@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 InputStream in, @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 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