Class CharStreams
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.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic CharSinkasCharSink(OutputSupplier<? extends Appendable> supplier) Deprecated.Returns a view of the givenAppendablesupplier as aCharSink.static CharSourceasCharSource(InputSupplier<? extends Readable> supplier) Deprecated.Returns a view of the givenReadablesupplier as aCharSource.static CharSourceasCharSource(String string) Deprecated.UseCharSource.wrap(CharSequence)instead.static WriterasWriter(Appendable target) Deprecated.Returns a Writer that sends all output to the givenAppendabletarget.static <R extends Readable & Closeable,W extends Appendable & Closeable>
longcopy(InputSupplier<R> from, OutputSupplier<W> to) Deprecated.OpensReadableandAppendableobjects from the given factories, copies all characters between the two, and closes them.copy(InputSupplier<R> from, Appendable to) Deprecated.Opens aReadableobject from the supplier, copies all characters to theAppendableobject, and closes the input.static longcopy(Readable from, Appendable to) Deprecated.Copies all characters between theReadableandAppendableobjects.static InputSupplier<Reader> join(InputSupplier<? extends Reader>... suppliers) Deprecated.Varargs form ofjoin(Iterable).static InputSupplier<Reader> join(Iterable<? extends InputSupplier<? extends Reader>> suppliers) Deprecated.Joins multipleReadersuppliers into a single supplier.static InputSupplier<InputStreamReader> newReaderSupplier(InputSupplier<? extends InputStream> in, Charset charset) Deprecated.Returns a factory that will supply instances ofInputStreamReader, using the givenInputStreamfactory and character set.static InputSupplier<StringReader> newReaderSupplier(String value) Deprecated.Returns a factory that will supply instances ofStringReaderthat read a string value.static OutputSupplier<OutputStreamWriter> newWriterSupplier(OutputSupplier<? extends OutputStream> out, Charset charset) Deprecated.Returns a factory that will supply instances ofOutputStreamWriter, using the givenOutputStreamfactory and character set.static WriterDeprecated.Returns aWriterthat simply discards written chars.readFirstLine(InputSupplier<R> supplier) Deprecated.readLines(InputSupplier<R> supplier) Deprecated.readLines(InputSupplier<R> supplier, LineProcessor<T> callback) Deprecated.Deprecated.Reads all of the lines from aReadableobject.static <T> TreadLines(Readable readable, LineProcessor<T> processor) Deprecated.Streams lines from aReadableobject, stopping when the processor returnsfalseor all lines have been read and returning the result produced by the processor.static voidDeprecated.Discardsncharacters of data from the reader.toString(InputSupplier<R> supplier) Deprecated.static Stringstatic <W extends Appendable & Closeable>
voidwrite(CharSequence from, OutputSupplier<W> to) Deprecated.Writes a character sequence (such as a string) to an appendable object from the given supplier.
-
Method Details
-
newReaderSupplier
Deprecated.Returns a factory that will supply instances ofStringReaderthat read a string value.- Parameters:
value- the string to read- Returns:
- the factory
-
asCharSource
Deprecated.UseCharSource.wrap(CharSequence)instead. This method is scheduled to be removed in Guava 16.0.Returns aCharSourcethat reads the given string value.- Since:
- 14.0
-
newReaderSupplier
public static InputSupplier<InputStreamReader> newReaderSupplier(InputSupplier<? extends InputStream> in, Charset charset) Deprecated.Returns a factory that will supply instances ofInputStreamReader, using the givenInputStreamfactory and character set.- Parameters:
in- the factory that will be used to open input streamscharset- the charset used to decode the input stream; seeCharsetsfor helpful predefined constants- Returns:
- the factory
-
newWriterSupplier
public static OutputSupplier<OutputStreamWriter> newWriterSupplier(OutputSupplier<? extends OutputStream> out, Charset charset) Deprecated.Returns a factory that will supply instances ofOutputStreamWriter, using the givenOutputStreamfactory and character set.- Parameters:
out- the factory that will be used to open output streamscharset- the charset used to encode the output stream; seeCharsetsfor helpful predefined constants- Returns:
- the factory
-
write
public static <W extends Appendable & Closeable> void write(CharSequence from, OutputSupplier<W> to) throws IOException Deprecated.Writes a character sequence (such as a string) to an appendable object from the given supplier.- Parameters:
from- the character sequence to writeto- the output supplier- Throws:
IOException- if an I/O error occurs
-
copy
public static <R extends Readable & Closeable,W extends Appendable & Closeable> long copy(InputSupplier<R> from, OutputSupplier<W> to) throws IOException Deprecated.OpensReadableandAppendableobjects from the given factories, copies all characters between the two, and closes them.- Parameters:
from- the input factoryto- the output factory- Returns:
- the number of characters copied
- Throws:
IOException- if an I/O error occurs
-
copy
public static <R extends Readable & Closeable> long copy(InputSupplier<R> from, Appendable to) throws IOException Deprecated.Opens aReadableobject from the supplier, copies all characters to theAppendableobject, and closes the input. Does not close or flush the output.- Parameters:
from- the input factoryto- the object to write to- Returns:
- the number of characters copied
- Throws:
IOException- if an I/O error occurs
-
copy
Deprecated.Copies all characters between theReadableandAppendableobjects. Does not close or flush either object.- Parameters:
from- the object to read fromto- the object to write to- Returns:
- the number of characters copied
- Throws:
IOException- if an I/O error occurs
-
toString
Deprecated.- Parameters:
r- the object to read from- Returns:
- a string containing all the characters
- Throws:
IOException- if an I/O error occurs
-
toString
public static <R extends Readable & Closeable> String toString(InputSupplier<R> supplier) throws IOException Deprecated.Returns the characters from aReadableinvalid input: '&'Closeableobject supplied by a factory as aString.- Parameters:
supplier- the factory to read from- Returns:
- a string containing all the characters
- Throws:
IOException- if an I/O error occurs
-
readFirstLine
public static <R extends Readable & Closeable> String readFirstLine(InputSupplier<R> supplier) throws IOException Deprecated.Reads the first line from aReadableinvalid input: '&'Closeableobject supplied by a factory. The line does not include line-termination characters, but does include other leading and trailing whitespace.- Parameters:
supplier- the factory to read from- Returns:
- the first line, or null if the reader is empty
- Throws:
IOException- if an I/O error occurs
-
readLines
public static <R extends Readable & Closeable> List<String> readLines(InputSupplier<R> supplier) throws IOException Deprecated.Reads all of the lines from aReadableinvalid input: '&'Closeableobject supplied by a factory. The lines do not include line-termination characters, but do include other leading and trailing whitespace.- Parameters:
supplier- the factory to read from- Returns:
- a mutable
Listcontaining all the lines - Throws:
IOException- if an I/O error occurs
-
readLines
Deprecated.Reads all of the lines from aReadableobject. 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 theFiles.readLines(java.io.File, java.nio.charset.Charset)andResources.readLines(java.net.URL, java.nio.charset.Charset, com.google.common.io.LineProcessor<T>)methods.- Parameters:
r- the object to read from- Returns:
- a mutable
Listcontaining all the lines - Throws:
IOException- if an I/O error occurs
-
readLines
Deprecated.Streams lines from aReadableobject, stopping when the processor returnsfalseor all lines have been read and returning the result produced by the processor. Does not closereadable. Note that this method may not fully consume the contents ofreadableif the processor stops processing early.- Throws:
IOException- if an I/O error occurs- Since:
- 14.0
-
readLines
public static <R extends Readable & Closeable,T> T readLines(InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException Deprecated.Streams lines from aReadableandCloseableobject supplied by a factory, stopping when our callback returns false, or we have read all of the lines.- Parameters:
supplier- the factory to read fromcallback- the LineProcessor to use to handle the lines- Returns:
- the output of processing the lines
- Throws:
IOException- if an I/O error occurs
-
join
public static InputSupplier<Reader> join(Iterable<? extends InputSupplier<? extends Reader>> suppliers) Deprecated.Joins multipleReadersuppliers 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
NullPointerExceptionif 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.
- Parameters:
suppliers- the suppliers to concatenate- Returns:
- a supplier that will return a reader containing the concatenated data
-
join
Deprecated.Varargs form ofjoin(Iterable). -
skipFully
Deprecated.Discardsncharacters of data from the reader. This method will block until the full amount has been skipped. Does not close the reader.- Parameters:
reader- the reader to read fromn- the number of characters to skip- Throws:
EOFException- if this stream reaches the end before skipping all the charactersIOException- if an I/O error occurs
-
nullWriter
Deprecated.Returns aWriterthat simply discards written chars.- Since:
- 15.0
-
asWriter
Deprecated.Returns a Writer that sends all output to the givenAppendabletarget. Closing the writer will close the target if it isCloseable, and flushing the writer will flush the target if it isFlushable.- Parameters:
target- the object to which output will be sent- Returns:
- a new Writer object, unless target is a Writer, in which case the target is returned
-
asCharSource
Deprecated.Returns a view of the givenReadablesupplier as aCharSource.This method is a temporary method provided for easing migration from suppliers to sources and sinks.
- Since:
- 15.0
-
asCharSink
Deprecated.Returns a view of the givenAppendablesupplier as aCharSink.This method is a temporary method provided for easing migration from suppliers to sources and sinks.
- Since:
- 15.0
-