@Immutable public class Streams extends Object
InputStream
s and OutputStream
s.Modifier and Type | Class and Description |
---|---|
static class |
Streams.ReaderThread
A pooled and cached daemon thread which runs tasks to read input streams.
|
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE
The buffer size used for reading and writing, which is 8192.
|
Modifier and Type | Method and Description |
---|---|
static void |
cat(InputStream in,
OutputStream out)
Copies the data from the given input stream to the given output stream
without closing them.
|
static void |
copy(InputStream in,
OutputStream out)
Copies the data from the given input stream to the given output stream
and always closes both streams - even if an exception
occurs.
|
public static final int BUFFER_SIZE
public static void cat(@WillNotClose InputStream in, @WillNotClose OutputStream out) throws IOException
OutputStream.flush()
unless an
IOException
occurs when writing to the output stream.
This hold true even if an IOException
occurs when reading from
the input stream.
This is a high performance implementation which uses a pooled background thread to fill a FIFO of pooled buffers which is concurrently flushed by the current thread. It performs best when used with unbuffered streams.
The name of this method is inspired by the Unix command line utility
cat
because you could use it to concatenate the contents
of multiple streams.
in
- the input stream.out
- the output stream.InputException
- if copying the data fails because of an
IOException
thrown by the input stream.IOException
- if copying the data fails because of an
IOException
thrown by the output stream.public static void copy(@WillClose InputStream in, @WillClose OutputStream out) throws IOException
This is a high performance implementation which uses a pooled background thread to fill a FIFO of pooled buffers which is concurrently flushed by the current thread. It performs best when used with unbuffered streams.
in
- the input stream.out
- the output stream.InputException
- if copying the data fails because of an
IOException
thrown by the input stream.IOException
- if copying the data fails because of an
IOException
thrown by the output stream.Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.