Class StreamUtil


  • public final class StreamUtil
    extends Object
    Helper class to provde generic stream functions.
    Author:
    Siegfried Goeschl
    • Constructor Detail

      • StreamUtil

        public StreamUtil()
    • Method Detail

      • createInputStream

        public static InputStream createInputStream​(Object source)
                                             throws IOException
        Create an input stream supporting the following types
        • String (using the UTF-8 encoded content)
        • File
        • byte[]
        • char[]
        • ByteArrayOutputStream
        • InputStream
        Parameters:
        source - the source object
        Returns:
        the created input stream
        Throws:
        IOException - creating the input stream failed
      • createOutputStream

        public static OutputStream createOutputStream​(Object target)
                                               throws IOException
        Create an output stream supporting the following types
        • File
        • String
        • OutputStream
        Parameters:
        target - the target object
        Returns:
        the output stream
        Throws:
        IOException - creating the output stream failed
      • copy

        public static long copy​(InputStream is,
                                OutputStream os)
                         throws IOException
        Pumps the input stream to the output stream.
        Parameters:
        is - the source input stream
        os - the target output stream
        Returns:
        the number of bytes copied
        Throws:
        IOException - the copying failed