Class StreamUtils


  • public class StreamUtils
    extends Object
    Stream copying utilities
    • Field Detail

      • DEFAULT_CHUNK_SIZE

        public static final int DEFAULT_CHUNK_SIZE
        Default size to use for reading buffers.
        See Also:
        Constant Field Values
    • Method Detail

      • copy

        public static long copy​(InputStream inputStream,
                                OutputStream outputStream)
                         throws IOException
        Copy the inputStream to the outputStream. Uses a buffer of the default size (DEFAULT_CHUNK_SIZE).
        Parameters:
        inputStream - The input stream to read
        outputStream - The output stream to write to
        Returns:
        The number of bytes read
        Throws:
        IOException - If a problem occurred accessing either stream
      • copy

        public static long copy​(InputStream inputStream,
                                OutputStream outputStream,
                                int bufferSize)
                         throws IOException
        Copy the inputStream to the outputStream using a buffer of the specified size
        Parameters:
        inputStream - The input stream to read
        outputStream - The output stream to write to
        bufferSize - The size of the buffer to use for reading
        Returns:
        The number of bytes read
        Throws:
        IOException - If a problem occurred accessing either stream
      • copy

        public static long copy​(Reader reader,
                                Writer writer)
                         throws IOException
        Copy the reader to the writer. Uses a buffer of the default size (DEFAULT_CHUNK_SIZE).
        Parameters:
        reader - The reader to read from
        writer - The writer to write to
        Returns:
        The number of bytes read
        Throws:
        IOException - If a problem occurred accessing reader or writer
      • copy

        public static long copy​(Reader reader,
                                Writer writer,
                                int bufferSize)
                         throws IOException
        Copy the reader to the writer using a buffer of the specified size
        Parameters:
        reader - The reader to read from
        writer - The writer to write to
        bufferSize - The size of the buffer to use for reading
        Returns:
        The number of bytes read
        Throws:
        IOException - If a problem occurred accessing either stream