Class Streams


  • public final class Streams
    extends Object
    Utilities methods for working with input and output streams.
    Author:
    Jonathan Locke, Igor Vaynberg
    • Method Detail

      • copyAndClose

        public static int copyAndClose​(InputStream in,
                                       OutputStream out)
                                throws IOException
        Writes the input stream to the output stream. Input is done without a Reader object, meaning that the input is copied in its raw form. After it is copied it will close the streams.
        Parameters:
        in - The input stream
        out - The output stream
        Returns:
        Number of bytes copied from one stream to the other
        Throws:
        IOException
      • copy

        public static int copy​(InputStream in,
                               OutputStream out)
                        throws IOException
        Writes the input stream to the output stream. Input is done without a Reader object, meaning that the input is copied in its raw form.
        Parameters:
        in - The input stream
        out - The output stream
        Returns:
        Number of bytes copied from one stream to the other
        Throws:
        IOException
      • copy

        public static int copy​(InputStream in,
                               OutputStream out,
                               int bufSize)
                        throws IOException
        Writes the input stream to the output stream. Input is done without a Reader object, meaning that the input is copied in its raw form.
        Parameters:
        in - The input stream
        out - The output stream
        bufSize - The buffer size. A good value is 4096.
        Returns:
        Number of bytes copied from one stream to the other
        Throws:
        IOException
      • loadFromXml

        public static void loadFromXml​(Properties properties,
                                       InputStream inputStream)
                                throws IOException
        Loads properties from an XML input stream into the provided properties object.
        Parameters:
        properties - The object to load the properties into
        inputStream -
        Throws:
        IOException - When the input stream could not be read from
      • readNonCaching

        public static InputStream readNonCaching​(URL url)
                                          throws IOException
        Sets the connection to a URL as non-caching and returns the input stream.
        Parameters:
        url - the url to read from
        Returns:
        the input stream for this url
        Throws:
        IOException - when a connection cannot be opened