Package ca.cgjennings.io
Class StreamPump
- java.lang.Object
-
- ca.cgjennings.io.StreamPump
-
public class StreamPump extends java.lang.Object
Provides high-performance copying from input streams to output streams and from readers to writers. This class is thread safe.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copy(java.io.InputStream in, java.io.OutputStream out)
Copy the bytes from one stream to another without closing either.static void
copy(java.io.Reader in, java.io.Writer out)
Copy the characters from a reader to a writer without closing either.static void
drain(java.io.InputStream in)
Reads an input stream until the end of the stream is reached.static int
getBufferSize()
Returns the current buffer size used for copy operations.static void
setBufferSize(int buffSize)
Sets the buffer size, in bytes, used for copy operations.
-
-
-
Method Detail
-
copy
public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
Copy the bytes from one stream to another without closing either.- Parameters:
in
- the stream to read fromout
- the stream to copy the read bytes to- Throws:
java.io.IOException
- if an I/O error occurs while copyingjava.lang.NullPointerException
- if either parameter isnull
-
drain
public static void drain(java.io.InputStream in) throws java.io.IOException
Reads an input stream until the end of the stream is reached. This is typically used when the stream is being read for the side effects of one or more stream filters attached to it, such as computing a CRC or hash value.- Parameters:
in
- the stream to empty- Throws:
java.io.IOException
- if an I/O error occurs while reading the stream
-
copy
public static void copy(java.io.Reader in, java.io.Writer out) throws java.io.IOException
Copy the characters from a reader to a writer without closing either.- Parameters:
in
- the source to copy fromout
- the destination to copy to (may use a different encoding)- Throws:
java.io.IOException
- if an I/O error occurs while copyingjava.lang.NullPointerException
- if either parameter isnull
-
setBufferSize
public static void setBufferSize(int buffSize)
Sets the buffer size, in bytes, used for copy operations. Any copy operations that are currently in use will continue to use the old buffer size, but all new copy operations after this method returns will use the new buffer size. The default buffer size was chosen after experimentation in a variety of conditions. Changing the buffer size is only recommended if you intend to experimentally customize the buffer size to a particular applicaiton.- Parameters:
buffSize
- the new buffer size, in bytes- Throws:
java.lang.IllegalArgumentException
- if the requested buffer size is less than 1 byte
-
getBufferSize
public static int getBufferSize()
Returns the current buffer size used for copy operations.- Returns:
- the buffer size, in bytes
- See Also:
setBufferSize(int)
-
-