Class StreamUtils


  • public class StreamUtils
    extends java.lang.Object
    Stream copying utilities
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_CHUNK_SIZE
      Default size to use for reading buffers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream)
      Copy the inputStream to the outputStream.
      static long copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream, int bufferSize)
      Copy the inputStream to the outputStream using a buffer of the specified size
      static long copy​(java.io.Reader reader, java.io.Writer writer)
      Copy the reader to the writer.
      static long copy​(java.io.Reader reader, java.io.Writer writer, int bufferSize)
      Copy the reader to the writer using a buffer of the specified size
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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​(java.io.InputStream inputStream,
                                java.io.OutputStream outputStream)
                         throws java.io.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:
        java.io.IOException - If a problem occurred accessing either stream
      • copy

        public static long copy​(java.io.InputStream inputStream,
                                java.io.OutputStream outputStream,
                                int bufferSize)
                         throws java.io.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:
        java.io.IOException - If a problem occurred accessing either stream
      • copy

        public static long copy​(java.io.Reader reader,
                                java.io.Writer writer)
                         throws java.io.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:
        java.io.IOException - If a problem occurred accessing reader or writer
      • copy

        public static long copy​(java.io.Reader reader,
                                java.io.Writer writer,
                                int bufferSize)
                         throws java.io.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:
        java.io.IOException - If a problem occurred accessing either stream