public final class CharStreams extends Object
| Modifier and Type | Method and Description |
|---|---|
static Reader |
concat(Iterable<? extends Reader> streams)
Concatenates the given
Readers into a single one. |
static Reader |
concat(Reader... streams)
Concatenates the given
Readers into a single one. |
static void |
copy(InputStream in,
Writer out)
Copies the content of the given
InputStream into the given
Writer using the system's default charset. |
static void |
copy(InputStream in,
Writer out,
Charset charset)
Copies the content of the given
InputStream into the given
Writer using the specified charset. |
static void |
copy(Reader in,
OutputStream out)
Copies the content of the given
Reader into the given
OutputStream using the system's default charset. |
static void |
copy(Reader in,
OutputStream out,
Charset charset)
Copies the content of the given
Reader into the given
OutputStream using the specified charset. |
static void |
copy(Reader in,
Writer out)
Copies the content of the given
Reader into the given
Writer. |
static boolean |
equal(Reader in1,
Reader in2)
Returns whether the given streams have the same content.
|
static Reader |
limit(Reader in,
long limit)
Returns an
Reader that will only supply characters from the
given Reader up to the specified limit. |
static String |
read(InputStream in)
Reads the whole content of the given
InputStream into a
String using the system's default charset. |
static String |
read(InputStream in,
Charset charset)
Reads the whole content of the given
InputStream into a
String using the specified charset. |
static String |
read(Reader in)
Reads the whole content of the given
Reader into a
String. |
static List<String> |
readLines(InputStream in)
Reads all the lines from the given source
InputStream using
the system's default charset. |
static List<String> |
readLines(InputStream in,
Charset charset)
Reads all the lines from the given source
InputStream using
the specified charset. |
static List<String> |
readLines(Reader in)
Reads all the lines from the given source
Reader. |
static Writer |
tee(Iterable<? extends Writer> streams)
Returns a
Writer that writes all characters written to it
to the given underlying streams. |
static Writer |
tee(Writer... streams)
Returns a
Writer that writes all characters written to it
to the given underlying streams. |
public static Reader concat(Reader... streams)
Readers into a single one. The given
streams will be read sequentially. Closing the concatenated stream
will close all the source streams. Note that the returned
Reader is not thread-safe and does not support
Reader.mark(int) and Reader.reset().streams - the streams to concatenate.Reader.NullPointerException - if streams is null or
if it contains a null reference.IllegalArgumentException - if streams is empty.public static Reader concat(Iterable<? extends Reader> streams)
Readers into a single one. The given
streams will be read sequentially. Closing the concatenated stream
will close all the source streams. Note that the returned
Reader is not thread-safe and does not support
Reader.mark(int) and Reader.reset().streams - the streams to concatenate.Reader.NullPointerException - if streams is null or
if it contains a null reference.IllegalArgumentException - if streams is empty.public static void copy(Reader in, Writer out) throws IOException
Reader into the given
Writer.in - the Reader to read from.out - the Reader to write on.NullPointerException - if one of the arguments is null.IOException - if an I/O error occurs during the process.public static void copy(InputStream in, Writer out) throws IOException
InputStream into the given
Writer using the system's default charset.in - the InputStream to read from.out - the Reader to write on.NullPointerException - if one of the arguments is null.IOException - if an I/O error occurs during the process.public static void copy(InputStream in, Writer out, Charset charset) throws IOException
InputStream into the given
Writer using the specified charset.in - the InputStream to read from.out - the Reader to write on.charset - the charset to use.NullPointerException - if one of the arguments is null.IOException - if an I/O error occurs during the process.public static void copy(Reader in, OutputStream out) throws IOException
Reader into the given
OutputStream using the system's default charset.in - the Reader to read from.out - the OutputStream to write on.NullPointerException - if one of the arguments is null.IOException - if an I/O error occurs during the process.public static void copy(Reader in, OutputStream out, Charset charset) throws IOException
Reader into the given
OutputStream using the specified charset.in - the Reader to read from.out - the OutputStream to write on.charset - the charset to use.NullPointerException - if one of the arguments is null.IOException - if an I/O error occurs during the process.public static boolean equal(Reader in1, Reader in2) throws IOException
in1 - the first stream.in2 - the second stream.true if the streams have the same content.IOException - if an I/O error occurs during the process.public static Reader limit(Reader in, long limit)
Reader that will only supply characters from the
given Reader up to the specified limit. The returned
Reader is thread-safe.in - the source stream.limit - the maximum number of characters to be read from in.Reader.NullPointerException - if in is null.IllegalArgumentException - if limit is negative.public static String read(Reader in) throws IOException
Reader into a
String.in - the stream to read.String.NullPointerException - if in is null.IOException - if the stream cannot be read.public static String read(InputStream in) throws IOException
InputStream into a
String using the system's default charset.in - the stream to read.String.NullPointerException - if in is null.IOException - if the stream cannot be read.public static String read(InputStream in, Charset charset) throws IOException
InputStream into a
String using the specified charset.in - the stream to read.charset - the stream's charset.String.NullPointerException - if one of the arguments is null.IOException - if the stream cannot be read.public static List<String> readLines(Reader in) throws IOException
Reader. Note that
the returned List is immutable.in - the stream to read.NullPointerException - if in is null.IOException - if the stream cannot be read.public static List<String> readLines(InputStream in) throws IOException
InputStream using
the system's default charset. Note that the returned List is
immutable.in - the stream to read.NullPointerException - if in is null.IOException - if the stream cannot be read.public static List<String> readLines(InputStream in, Charset charset) throws IOException
InputStream using
the specified charset. Note that the returned List is immutable.in - the stream to read.charset - the charset to use.NullPointerException - if one of the arguments is null.IOException - if the stream cannot be read.public static Writer tee(Writer... streams)
Writer that writes all characters written to it
to the given underlying streams. Named after the Unix 'tee' command.
The returned instance is not thread-safe.streams - the streams to write to.Writer.NullPointerException - if streams is null or
if it contains a null reference.public static Writer tee(Iterable<? extends Writer> streams)
Writer that writes all characters written to it
to the given underlying streams. Named after the Unix 'tee' command.
The returned instance is not thread-safe.streams - the streams to write to.Writer.NullPointerException - if streams is null or
if it contains a null reference.Copyright © 2012–2015. All rights reserved.