Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_COPY_BUFFER_SIZE
The default buffer size (1024) used by
copyStream and copyReader
and by the copyReader/copyStream methods if a zero or negative buffer size is supplied. |
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(Closeable closeable)
Closes the object quietly, catching rather than throwing IOException.
|
static void |
closeQuietly(Socket socket)
Closes the socket quietly, catching rather than throwing IOException.
|
static long |
copyReader(Reader source,
Writer dest)
Same as
copyReader(source, dest, DEFAULT_COPY_BUFFER_SIZE); |
static long |
copyReader(Reader source,
Writer dest,
int bufferSize)
Copies the contents of a Reader to a Writer using a
copy buffer of a given size.
|
static long |
copyReader(Reader source,
Writer dest,
int bufferSize,
long streamSize,
CopyStreamListener listener)
Copies the contents of a Reader to a Writer using a
copy buffer of a given size and notifies the provided
CopyStreamListener of the progress of the copy operation by calling
its bytesTransferred(long, int) method after each write to the
destination.
|
static long |
copyStream(InputStream source,
OutputStream dest)
Same as
copyStream(source, dest, DEFAULT_COPY_BUFFER_SIZE); |
static long |
copyStream(InputStream source,
OutputStream dest,
int bufferSize)
Copies the contents of an InputStream to an OutputStream using a
copy buffer of a given size.
|
static long |
copyStream(InputStream source,
OutputStream dest,
int bufferSize,
long streamSize,
CopyStreamListener listener)
Copies the contents of an InputStream to an OutputStream using a
copy buffer of a given size and notifies the provided
CopyStreamListener of the progress of the copy operation by calling
its bytesTransferred(long, int) method after each write to the
destination.
|
static long |
copyStream(InputStream source,
OutputStream dest,
int bufferSize,
long streamSize,
CopyStreamListener listener,
boolean flush)
Copies the contents of an InputStream to an OutputStream using a
copy buffer of a given size and notifies the provided
CopyStreamListener of the progress of the copy operation by calling
its bytesTransferred(long, int) method after each write to the
destination.
|
public static final int DEFAULT_COPY_BUFFER_SIZE
copyStream
and copyReader
and by the copyReader/copyStream methods if a zero or negative buffer size is supplied.public static final long copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener, boolean flush) throws CopyStreamException
The contents of the InputStream are read until the end of the stream is reached, but neither the source nor the destination are closed. You must do this yourself outside of the method call. The number of bytes read/written is returned.
source
- The source InputStream.dest
- The destination OutputStream.bufferSize
- The number of bytes to buffer during the copy.
A zero or negative value means to use DEFAULT_COPY_BUFFER_SIZE
.streamSize
- The number of bytes in the stream being copied.
Should be set to CopyStreamEvent.UNKNOWN_STREAM_SIZE if unknown.
Not currently used (though it is passed to CopyStreamListener.bytesTransferred(long, int, long)
listener
- The CopyStreamListener to notify of progress. If
this parameter is null, notification is not attempted.flush
- Whether to flush the output stream after every
write. This is necessary for interactive sessions that rely on
buffered streams. If you don't flush, the data will stay in
the stream buffer.CopyStreamException
- If an error occurs while reading from the
source or writing to the destination. The CopyStreamException
will contain the number of bytes confirmed to have been
transferred before an
IOException occurred, and it will also contain the IOException
that caused the error. These values can be retrieved with
the CopyStreamException getTotalBytesTransferred() and
getIOException() methods.public static final long copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException
The contents of the InputStream are read until the end of the stream is reached, but neither the source nor the destination are closed. You must do this yourself outside of the method call. The number of bytes read/written is returned.
source
- The source InputStream.dest
- The destination OutputStream.bufferSize
- The number of bytes to buffer during the copy.
A zero or negative value means to use DEFAULT_COPY_BUFFER_SIZE
.streamSize
- The number of bytes in the stream being copied.
Should be set to CopyStreamEvent.UNKNOWN_STREAM_SIZE if unknown.
Not currently used (though it is passed to CopyStreamListener.bytesTransferred(long, int, long)
listener
- The CopyStreamListener to notify of progress. If
this parameter is null, notification is not attempted.CopyStreamException
- If an error occurs while reading from the
source or writing to the destination. The CopyStreamException
will contain the number of bytes confirmed to have been
transferred before an
IOException occurred, and it will also contain the IOException
that caused the error. These values can be retrieved with
the CopyStreamException getTotalBytesTransferred() and
getIOException() methods.public static final long copyStream(InputStream source, OutputStream dest, int bufferSize) throws CopyStreamException
source
- The source InputStream.dest
- The destination OutputStream.bufferSize
- The number of bytes to buffer during the copy.
A zero or negative value means to use DEFAULT_COPY_BUFFER_SIZE
.CopyStreamException
- If an error occurs while reading from the
source or writing to the destination. The CopyStreamException
will contain the number of bytes confirmed to have been
transferred before an
IOException occurred, and it will also contain the IOException
that caused the error. These values can be retrieved with
the CopyStreamException getTotalBytesTransferred() and
getIOException() methods.public static final long copyStream(InputStream source, OutputStream dest) throws CopyStreamException
copyStream(source, dest, DEFAULT_COPY_BUFFER_SIZE);
source
- where to copy fromdest
- where to copy toCopyStreamException
- on errorpublic static final long copyReader(Reader source, Writer dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException
The contents of the Reader are read until its end is reached, but neither the source nor the destination are closed. You must do this yourself outside of the method call. The number of characters read/written is returned.
source
- The source Reader.dest
- The destination writer.bufferSize
- The number of characters to buffer during the copy.
A zero or negative value means to use DEFAULT_COPY_BUFFER_SIZE
.streamSize
- The number of characters in the stream being copied.
Should be set to CopyStreamEvent.UNKNOWN_STREAM_SIZE if unknown.
Not currently used (though it is passed to CopyStreamListener.bytesTransferred(long, int, long)
listener
- The CopyStreamListener to notify of progress. If
this parameter is null, notification is not attempted.CopyStreamException
- If an error occurs while reading from the
source or writing to the destination. The CopyStreamException
will contain the number of bytes confirmed to have been
transferred before an
IOException occurred, and it will also contain the IOException
that caused the error. These values can be retrieved with
the CopyStreamException getTotalBytesTransferred() and
getIOException() methods.public static final long copyReader(Reader source, Writer dest, int bufferSize) throws CopyStreamException
source
- The source Reader.dest
- The destination writer.bufferSize
- The number of characters to buffer during the copy.
A zero or negative value means to use DEFAULT_COPY_BUFFER_SIZE
.CopyStreamException
- If an error occurs while reading from the
source or writing to the destination. The CopyStreamException
will contain the number of bytes confirmed to have been
transferred before an
IOException occurred, and it will also contain the IOException
that caused the error. These values can be retrieved with
the CopyStreamException getTotalBytesTransferred() and
getIOException() methods.public static final long copyReader(Reader source, Writer dest) throws CopyStreamException
copyReader(source, dest, DEFAULT_COPY_BUFFER_SIZE);
source
- where to copy fromdest
- where to copy toCopyStreamException
- on errorpublic static void closeQuietly(Closeable closeable)
closeable
- the object to close, may be null
public static void closeQuietly(Socket socket)
socket
- the socket to close, may be null
Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.