public class StreamCopier extends Object
InputStream to an
OutputStream.| Modifier and Type | Class and Description |
|---|---|
static interface |
StreamCopier.ProgressListener
Interface for objects that want to be notified about the progress of a
copy(InputStream, OutputStream, ProgressListener)
operation. |
| Constructor and Description |
|---|
StreamCopier() |
| Modifier and Type | Method and Description |
|---|---|
static long |
copy(InputStream source,
OutputStream destination)
Copies as many bytes as possible (i.e. until
InputStream.read()
returns -1) from the source input stream to the destination
output stream. |
static long |
copy(InputStream source,
OutputStream destination,
long length)
Copies
length bytes from the source input stream to the
destination output stream. |
static long |
copy(InputStream source,
OutputStream destination,
StreamCopier.ProgressListener progressListener)
Copies as many bytes as possible (i.e. until
InputStream.read()
returns -1) from the source input stream to the destination
output stream. |
static long |
copy(InputStream source,
OutputStream destination,
StreamCopier.ProgressListener progressListener,
long length)
Copies
length bytes from the source input stream to the
destination output stream. |
static long |
findLength(InputStream source)
Finds the length of the input stream by reading until
InputStream.read(byte[]) returns -1. |
static void |
setBufferSize(int bufferSize)
Sets the buffer size for following transfers.
|
public static void setBufferSize(int bufferSize)
bufferSize - The new buffer sizepublic static long copy(InputStream source, OutputStream destination, StreamCopier.ProgressListener progressListener, long length) throws IOException
length bytes from the source input stream to the
destination output stream. If length is -1 as
much bytes as possible will be copied (i.e. until
InputStream.read() returns -1 to signal the end of
the stream).source - The input stream to read fromdestination - The output stream to write toprogressListener - A progress listener that is notified during copying (may be
null)length - The number of bytes to copyIOException - if an I/O error occurspublic static long copy(InputStream source, OutputStream destination, long length) throws IOException
length bytes from the source input stream to the
destination output stream. If length is -1 as
much bytes as possible will be copied (i.e. until
InputStream.read() returns -1 to signal the end of
the stream).source - The input stream to read fromdestination - The output stream to write tolength - The number of bytes to copyIOException - if an I/O error occurspublic static long copy(InputStream source, OutputStream destination, StreamCopier.ProgressListener progressListener) throws IOException
InputStream.read()
returns -1) from the source input stream to the destination
output stream.source - The input stream to read fromdestination - The output stream to write toprogressListener - A progress listener that is notified during copying (may be
null)IOException - if an I/O error occurspublic static long copy(InputStream source, OutputStream destination) throws IOException
InputStream.read()
returns -1) from the source input stream to the destination
output stream.source - The input stream to read fromdestination - The output stream to write toIOException - if an I/O error occurspublic static long findLength(InputStream source) throws IOException
InputStream.read(byte[]) returns -1.source - The input stream to measureIOException - if an I/O error occursCopyright © 2026. All rights reserved.