@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) @ThreadSafe public final class Streams extends Object
InputStreams and
OutputStreams.| Modifier and Type | Class and Description |
|---|---|
private static class |
Streams.Buffer
A buffer for I/O.
|
static class |
Streams.Reader
A pooled and cached daemon thread which reads input streams.
|
private static class |
Streams.ReaderFactory
A factory for reader threads.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE
The buffer size used for reading and writing.
|
private static ExecutorService |
executor |
private static int |
FIFO_SIZE
The size of the FIFO used for exchanging I/O buffers between a reader
thread and a writer thread.
|
| Modifier | Constructor and Description |
|---|---|
private |
Streams()
You cannot instantiate this class.
|
| 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
private static final ExecutorService executor
private static final int FIFO_SIZE
public static void cat(InputStream in, 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 in the input stream.IOException - if copying the data fails because of an
IOException in the output stream.public static void copy(InputStream in, 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 in the input stream.IOException - if copying the data fails because of an
IOException in the output stream.Copyright © 2004-2011 Schlichtherle IT Services. All Rights Reserved.