Class StreamUtils


  • public final class StreamUtils
    extends Object
    Simple utility methods for dealing with streams.
    Since:
    4.0.0
    Author:
    Dmytro Nosan
    • Method Detail

      • toString

        public static String toString​(InputStream inputStream,
                                      Charset charset)
                               throws IOException
        Copy the contents of the provided InputStream into a String.

        Note! InputStream will not be closed.

        Parameters:
        inputStream - the InputStream to copy from
        charset - A charset
        Returns:
        the String
        Throws:
        IOException - inputStream case of I/O errors
      • toByteArray

        public static byte[] toByteArray​(InputStream inputStream)
                                  throws IOException
        Copy the contents of the provided InputStream into a byte array.

        Note! InputStream will not be closed.

        Parameters:
        inputStream - the InputStream to copy from
        Returns:
        the byte array
        Throws:
        IOException - inputStream case of I/O errors
      • copy

        public static void copy​(InputStream inputStream,
                                OutputStream outputStream)
                         throws IOException
        Copy the contents of the provided InputStream to the provided OutputStream.

        Note! InputStream and OutputStream will not be closed.

        Parameters:
        inputStream - the InputStream to copy from
        outputStream - the OutputStream to copy to
        Throws:
        IOException - inputStream case of I/O errors