Class StreamUtils


  • public final class StreamUtils
    extends Object
    Stream utilities.
    • Method Detail

      • transfer

        public static void transfer​(InputStream in,
                                    OutputStream out)
                             throws IOException
        Transfers the contents of the given input stream to the given output stream. This implementation uses a large shared buffer and is therefore single-threaded.
        Parameters:
        in - The input stream.
        out - The output stream.
        Throws:
        IOException - If an error occurs.
      • toString

        public static String toString​(InputStream in)
                               throws IOException
        Reads the contents of the given input stream as a UTF8 string.
        Parameters:
        in - The input stream.
        Returns:
        The string.
        Throws:
        IOException - If an error occurs.
      • toString

        public static String toString​(ByteArrayOutputStream out)
        Reads the contents of the given output stream as a UTF8 string.
        Parameters:
        out - The output stream.
        Returns:
        The string.
      • toPrintStream

        public static PrintStream toPrintStream​(OutputStream out,
                                                boolean autoFlush)
        Wraps the given output stream as a PrintStream that uses UTF8 encoding.
        Parameters:
        out - The stream to wrap.
        autoFlush - true If stream should flush on each line.
        Returns:
        The stream.
      • toLines

        public static List<String> toLines​(InputStream in)
                                    throws IOException
        Reads the contents of the given input stream as a list of UTF8 lines.
        Parameters:
        in - The input stream.
        Returns:
        The list.
        Throws:
        IOException - If an error occurs.