Class IOStreamUtil

    • Constructor Summary

      Constructors 
      Constructor Description
      IOStreamUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean copy​(java.io.InputStream source, java.io.OutputStream destination)
      Simple copy of an input stream to an output stream.
      static java.io.BufferedInputStream getBufferedInputStream​(java.lang.String uri)
      Get a buffered input stream from the uri given in parameter.
      static java.io.BufferedInputStream getBufferedInputStream​(java.lang.String uri, int bufferSize)
      Get a buffered input stream from the uri given in parameter.
      static java.io.BufferedOutputStream getBufferedOutputStream​(java.lang.String uri)
      Get a buffered output stream to the uri given in parameter.
      static java.io.BufferedOutputStream getBufferedOutputStream​(java.lang.String uri, int bufferSize)
      Get a buffered output stream to the uri given in parameter.
      static java.io.InputStream getInputStream​(java.lang.String uri)
      Open an InputStream from the resource located by the given uri.
      static java.io.OutputStream getOutputStream​(java.lang.String uri)
      Get an output stream to the uri given in parameter.
      • Methods inherited from class java.lang.Object

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

      • IOStreamUtil

        public IOStreamUtil()
    • Method Detail

      • getInputStream

        public static java.io.InputStream getInputStream​(java.lang.String uri)
                                                  throws java.io.IOException
        Open an InputStream from the resource located by the given uri. The returned stream can be:
        • a FileInputStream if the resource is a file on a local system;
        • a BufferedInputStream if the resource is an url or a location on a remote system;
        Parameters:
        uri - the location of the resource
        Returns:
        the input stream opened to the resource
        Throws:
        java.io.IOException - if an error occurs.
      • getBufferedInputStream

        public static java.io.BufferedInputStream getBufferedInputStream​(java.lang.String uri)
                                                                  throws java.io.IOException
        Get a buffered input stream from the uri given in parameter.
        Parameters:
        uri - the uri source of the input stream.
        Returns:
        a buffered input stream.
        Throws:
        java.io.IOException - if the stream cannot be set up.
      • getBufferedInputStream

        public static java.io.BufferedInputStream getBufferedInputStream​(java.lang.String uri,
                                                                         int bufferSize)
                                                                  throws java.io.IOException
        Get a buffered input stream from the uri given in parameter. The input stream buffer size is given by the bufferSize parameter. If the buffer size is less than 1, the buffered input stream created have a default buffer size.
        Parameters:
        uri - the uri source of the input stream.
        bufferSize - the size of the buffer
        Returns:
        a buffered input stream.
        Throws:
        java.io.IOException - if the stream cannot be set up.
      • getOutputStream

        public static java.io.OutputStream getOutputStream​(java.lang.String uri)
                                                    throws java.io.IOException
        Get an output stream to the uri given in parameter.
        Parameters:
        uri - the uri of the resource outputed
        Returns:
        an output stream to the resource.
        Throws:
        java.io.IOException - if the output stream cannot be set up.
      • getBufferedOutputStream

        public static java.io.BufferedOutputStream getBufferedOutputStream​(java.lang.String uri)
                                                                    throws java.io.IOException
        Get a buffered output stream to the uri given in parameter.
        Parameters:
        uri - the uri source of the output stream.
        Returns:
        a buffered output stream.
        Throws:
        java.io.IOException - if the stream cannot be set up.
        See Also:
        getBufferedOutputStream(String, int)
      • getBufferedOutputStream

        public static java.io.BufferedOutputStream getBufferedOutputStream​(java.lang.String uri,
                                                                           int bufferSize)
                                                                    throws java.io.IOException
        Get a buffered output stream to the uri given in parameter. The output stream buffer size is given by the bufferSize parameter. If the buffer size is less than 1, the buffered output stream created have a default buffer size.
        Parameters:
        uri - the uri source of the output stream.
        bufferSize - the size of the buffer
        Returns:
        a buffered output stream.
        Throws:
        java.io.IOException - if the stream cannot be set up.
      • copy

        public static boolean copy​(java.io.InputStream source,
                                   java.io.OutputStream destination)
        Simple copy of an input stream to an output stream.
        Parameters:
        source - Input stream to the source
        destination - Output stream to the destination
        Returns:
        true if the copy was successfull, false if not