@Beta
public final class CharStreams
extends java.lang.Object
All method parameters must be non-null unless documented otherwise.
Some of the methods in this class take arguments with a generic type of
Readable & Closeable. A Reader implements both of
those interfaces. Similarly for Appendable & Closeable and
Writer.
| Modifier and Type | Method and Description |
|---|---|
static CharSink |
asCharSink(OutputSupplier<? extends java.lang.Appendable> supplier)
Deprecated.
Convert all
OutputSupplier<? extends Appendable>
implementations to extend CharSink or provide a method for
viewing the object as a CharSink. This method is scheduled
for removal in Guava 18.0. |
static CharSource |
asCharSource(InputSupplier<? extends java.lang.Readable> supplier)
Deprecated.
Convert all
InputSupplier<? extends Readable>
implementations to extend CharSource or provide a method for
viewing the object as a CharSource. This method is scheduled
for removal in Guava 18.0. |
static java.io.Writer |
asWriter(java.lang.Appendable target)
Returns a Writer that sends all output to the given
Appendable
target. |
static <R extends java.lang.Readable & java.io.Closeable> |
copy(InputSupplier<R> from,
java.lang.Appendable to)
Deprecated.
Use
CharSource.copyTo(Appendable) instead. This method
is scheduled for removal in Guava 18.0. |
static <R extends java.lang.Readable & java.io.Closeable,W extends java.lang.Appendable & java.io.Closeable> |
copy(InputSupplier<R> from,
OutputSupplier<W> to)
Deprecated.
Use {@link CharSource#copyTo(CharSink) instead. This method is
scheduled for removal in Guava 18.0.
|
static long |
copy(java.lang.Readable from,
java.lang.Appendable to)
Copies all characters between the
Readable and Appendable
objects. |
static InputSupplier<java.io.Reader> |
join(InputSupplier<? extends java.io.Reader>... suppliers)
Deprecated.
Use
CharSource.concat(CharSource[]) instead. This
method is scheduled for removal in Guava 18.0. |
static InputSupplier<java.io.Reader> |
join(java.lang.Iterable<? extends InputSupplier<? extends java.io.Reader>> suppliers)
Deprecated.
Use
CharSource.concat(Iterable) instead. This method
is scheduled for removal in Guava 18.0. |
static InputSupplier<java.io.InputStreamReader> |
newReaderSupplier(InputSupplier<? extends java.io.InputStream> in,
java.nio.charset.Charset charset)
Deprecated.
Use
ByteSource.asCharSource(Charset) instead. This
method is scheduled for removal in Guava 18.0. |
static InputSupplier<java.io.StringReader> |
newReaderSupplier(java.lang.String value)
Deprecated.
Use
CharSource#wrap(CharSequence} instead. This method
is scheduled for removal in Guava 18.0. |
static OutputSupplier<java.io.OutputStreamWriter> |
newWriterSupplier(OutputSupplier<? extends java.io.OutputStream> out,
java.nio.charset.Charset charset)
Deprecated.
Use
ByteSink.asCharSink(Charset) instead. This method
is scheduled for removal in Guava 18.0. |
static java.io.Writer |
nullWriter()
Returns a
Writer that simply discards written chars. |
static <R extends java.lang.Readable & java.io.Closeable> |
readFirstLine(InputSupplier<R> supplier)
Deprecated.
Use
CharSource.readFirstLine() instead. This method is
scheduled for removal in Guava 18.0. |
static <R extends java.lang.Readable & java.io.Closeable> |
readLines(InputSupplier<R> supplier)
Deprecated.
Use
CharSource.readLines() instead, but note that it
returns an ImmutableList. This method is scheduled for removal
in Guava 18.0. |
static <R extends java.lang.Readable & java.io.Closeable,T> |
readLines(InputSupplier<R> supplier,
LineProcessor<T> callback)
Deprecated.
Use
CharSource.readLines(LineProcessor) instead. This
method is scheduled for removal in Guava 18.0. |
static java.util.List<java.lang.String> |
readLines(java.lang.Readable r)
Reads all of the lines from a
Readable object. |
static <T> T |
readLines(java.lang.Readable readable,
LineProcessor<T> processor)
Streams lines from a
Readable object, stopping when the processor
returns false or all lines have been read and returning the result
produced by the processor. |
static void |
skipFully(java.io.Reader reader,
long n)
Discards
n characters of data from the reader. |
static <R extends java.lang.Readable & java.io.Closeable> |
toString(InputSupplier<R> supplier)
Deprecated.
Use
CharSource.read() instead. This method is
scheduled for removal in Guava 18.0. |
static java.lang.String |
toString(java.lang.Readable r)
Reads all characters from a
Readable object into a String. |
static <W extends java.lang.Appendable & java.io.Closeable> |
write(java.lang.CharSequence from,
OutputSupplier<W> to)
Deprecated.
Use
CharSink.write(CharSequence) instead. This method
is scheduled for removal in Guava 18.0. |
@Deprecated public static InputSupplier<java.io.StringReader> newReaderSupplier(java.lang.String value)
CharSource#wrap(CharSequence} instead. This method
is scheduled for removal in Guava 18.0.StringReader that
read a string value.value - the string to read@Deprecated public static InputSupplier<java.io.InputStreamReader> newReaderSupplier(InputSupplier<? extends java.io.InputStream> in, java.nio.charset.Charset charset)
ByteSource.asCharSource(Charset) instead. This
method is scheduled for removal in Guava 18.0.InputStreamReader,
using the given InputStream factory and character set.in - the factory that will be used to open input streamscharset - the charset used to decode the input stream; see Charsets for helpful predefined constants@Deprecated public static OutputSupplier<java.io.OutputStreamWriter> newWriterSupplier(OutputSupplier<? extends java.io.OutputStream> out, java.nio.charset.Charset charset)
ByteSink.asCharSink(Charset) instead. This method
is scheduled for removal in Guava 18.0.OutputStreamWriter,
using the given OutputStream factory and character set.out - the factory that will be used to open output streamscharset - the charset used to encode the output stream; see Charsets for helpful predefined constants@Deprecated
public static <W extends java.lang.Appendable & java.io.Closeable> void write(java.lang.CharSequence from,
OutputSupplier<W> to)
throws java.io.IOException
CharSink.write(CharSequence) instead. This method
is scheduled for removal in Guava 18.0.from - the character sequence to writeto - the output supplierjava.io.IOException - if an I/O error occurs@Deprecated public static <R extends java.lang.Readable & java.io.Closeable,W extends java.lang.Appendable & java.io.Closeable> long copy(InputSupplier<R> from, OutputSupplier<W> to) throws java.io.IOException
Readable and Appendable objects from the
given factories, copies all characters between the two, and closes
them.from - the input factoryto - the output factoryjava.io.IOException - if an I/O error occurs@Deprecated public static <R extends java.lang.Readable & java.io.Closeable> long copy(InputSupplier<R> from, java.lang.Appendable to) throws java.io.IOException
CharSource.copyTo(Appendable) instead. This method
is scheduled for removal in Guava 18.0.Readable object from the supplier, copies all characters
to the Appendable object, and closes the input. Does not close
or flush the output.from - the input factoryto - the object to write tojava.io.IOException - if an I/O error occurspublic static long copy(java.lang.Readable from,
java.lang.Appendable to)
throws java.io.IOException
Readable and Appendable
objects. Does not close or flush either object.from - the object to read fromto - the object to write tojava.io.IOException - if an I/O error occurspublic static java.lang.String toString(java.lang.Readable r)
throws java.io.IOException
Readable object into a String.
Does not close the Readable.r - the object to read fromjava.io.IOException - if an I/O error occurs@Deprecated public static <R extends java.lang.Readable & java.io.Closeable> java.lang.String toString(InputSupplier<R> supplier) throws java.io.IOException
CharSource.read() instead. This method is
scheduled for removal in Guava 18.0.Readable & Closeable object
supplied by a factory as a String.supplier - the factory to read fromjava.io.IOException - if an I/O error occurs@Deprecated public static <R extends java.lang.Readable & java.io.Closeable> java.lang.String readFirstLine(InputSupplier<R> supplier) throws java.io.IOException
CharSource.readFirstLine() instead. This method is
scheduled for removal in Guava 18.0.Readable & Closeable object
supplied by a factory. The line does not include line-termination
characters, but does include other leading and trailing whitespace.supplier - the factory to read fromjava.io.IOException - if an I/O error occurs@Deprecated public static <R extends java.lang.Readable & java.io.Closeable> java.util.List<java.lang.String> readLines(InputSupplier<R> supplier) throws java.io.IOException
CharSource.readLines() instead, but note that it
returns an ImmutableList. This method is scheduled for removal
in Guava 18.0.Readable & Closeable object
supplied by a factory. The lines do not include line-termination
characters, but do include other leading and trailing whitespace.supplier - the factory to read fromList containing all the linesjava.io.IOException - if an I/O error occurspublic static java.util.List<java.lang.String> readLines(java.lang.Readable r)
throws java.io.IOException
Readable object. The lines do
not include line-termination characters, but do include other
leading and trailing whitespace.
Does not close the Readable. If reading files or resources you
should use the Files.readLines(java.io.File, java.nio.charset.Charset) and Resources.readLines(java.net.URL, java.nio.charset.Charset, net.tribe7.common.io.LineProcessor<T>)
methods.
r - the object to read fromList containing all the linesjava.io.IOException - if an I/O error occurspublic static <T> T readLines(java.lang.Readable readable,
LineProcessor<T> processor)
throws java.io.IOException
Readable object, stopping when the processor
returns false or all lines have been read and returning the result
produced by the processor. Does not close readable. Note that this
method may not fully consume the contents of readable if the
processor stops processing early.java.io.IOException - if an I/O error occurs@Deprecated public static <R extends java.lang.Readable & java.io.Closeable,T> T readLines(InputSupplier<R> supplier, LineProcessor<T> callback) throws java.io.IOException
CharSource.readLines(LineProcessor) instead. This
method is scheduled for removal in Guava 18.0.Readable and Closeable object
supplied by a factory, stopping when our callback returns false, or we
have read all of the lines.supplier - the factory to read fromcallback - the LineProcessor to use to handle the linesjava.io.IOException - if an I/O error occurs@Deprecated public static InputSupplier<java.io.Reader> join(java.lang.Iterable<? extends InputSupplier<? extends java.io.Reader>> suppliers)
CharSource.concat(Iterable) instead. This method
is scheduled for removal in Guava 18.0.Reader suppliers into a single supplier.
Reader returned from the supplier will contain the concatenated data
from the readers of the underlying suppliers.
Reading from the joined reader will throw a NullPointerException
if any of the suppliers are null or return null.
Only one underlying reader will be open at a time. Closing the joined reader will close the open underlying reader.
suppliers - the suppliers to concatenate@Deprecated public static InputSupplier<java.io.Reader> join(InputSupplier<? extends java.io.Reader>... suppliers)
CharSource.concat(CharSource[]) instead. This
method is scheduled for removal in Guava 18.0.join(Iterable).public static void skipFully(java.io.Reader reader,
long n)
throws java.io.IOException
n characters of data from the reader. This method
will block until the full amount has been skipped. Does not close the
reader.reader - the reader to read fromn - the number of characters to skipjava.io.EOFException - if this stream reaches the end before skipping all
the charactersjava.io.IOException - if an I/O error occurspublic static java.io.Writer nullWriter()
Writer that simply discards written chars.public static java.io.Writer asWriter(java.lang.Appendable target)
Appendable
target. Closing the writer will close the target if it is Closeable, and flushing the writer will flush the target if it is Flushable.target - the object to which output will be sent@Deprecated public static CharSource asCharSource(InputSupplier<? extends java.lang.Readable> supplier)
InputSupplier<? extends Readable>
implementations to extend CharSource or provide a method for
viewing the object as a CharSource. This method is scheduled
for removal in Guava 18.0.Readable supplier as a
CharSource.
This method is a temporary method provided for easing migration from suppliers to sources and sinks.
@Deprecated public static CharSink asCharSink(OutputSupplier<? extends java.lang.Appendable> supplier)
OutputSupplier<? extends Appendable>
implementations to extend CharSink or provide a method for
viewing the object as a CharSink. This method is scheduled
for removal in Guava 18.0.Appendable supplier as a
CharSink.
This method is a temporary method provided for easing migration from suppliers to sources and sinks.