@Immutable public 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.ReaderThread
A pooled and cached daemon thread which runs tasks to read input streams.
|
private static class |
Streams.ReaderThreadFactory
A factory for reader threads.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE
The buffer size used for reading and writing, which is 8192.
|
private static ExecutorService |
executor |
(package 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() |
| Modifier and Type | Method and Description |
|---|---|
private static void |
cancel(Future<?> result)
Cancels the reader thread synchronously.
|
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
static final int FIFO_SIZE
private static void cancel(Future<?> result)
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-2012 Schlichtherle IT Services. All Rights Reserved.