Top Description Inners Constructors Methods
com.google.common.io

public abstract Class CharSource

extends Object
Class Inheritance
Known Direct Subclasses
com.google.common.io.CharSource.CharSequenceCharSource, com.google.common.io.CharSource.ConcatenatedCharSource, com.google.common.io.ByteSource.AsCharSource
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

A readable source of characters, such as a text file. Unlike a Reader, a CharSource is not an open, stateful stream of characters that can be read and closed. Instead, it is an immutable supplier of Reader instances.

CharSource provides two kinds of methods:

Several methods in this class, such as readLines(), break the contents of the source into lines. Like BufferedReader, these methods break lines on any of \n, \r or \r\n, do not include the line separator in each line and do not consider there to be an empty line at the end if the contents are terminated with a line separator.

Any ByteSource containing text encoded with a specific character encoding may be viewed as a CharSource using ByteSource#asCharSource(Charset).

Note: In general, CharSource is intended to be used for "file-like" sources that provide readers that are:

Author
Colin Decker
Since
14.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
CharSource.AsByteSource

A byte source that reads chars from this source and encodes them as bytes using a charset.

private static class
private static class
private static class
private static class
CharSource.StringCharSource

Subclass specialized for string instances.

Constructor Summary

AccessConstructor and Description
protected
CharSource()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
public ByteSource
asByteSource(Charset charset)

Returns a ByteSource view of this char source that encodes chars read from this source as bytes using the given Charset.

public static CharSource

Returns:

a CharSource containing the concatenated data
concat
(Iterable<? extends CharSource>
the sources to concatenate
sources
)

Concatenates multiple CharSource instances into a single source.

public static CharSource

Returns:

a CharSource containing the concatenated data
concat
(Iterator<? extends CharSource>
the sources to concatenate
sources
)

Concatenates multiple CharSource instances into a single source.

public static CharSource

Returns:

a CharSource containing the concatenated data
concat
(CharSource...
the sources to concatenate
sources
)

Concatenates multiple CharSource instances into a single source.

public long

Returns:

the number of characters copied
copyTo
(Appendable appendable)

Appends the contents of this source to the given Appendable (such as a Writer).

public long

Returns:

the number of characters copied
copyTo
(CharSink sink)

Copies the contents of this source to the given sink.

private long
public static CharSource
empty()

Returns an immutable CharSource that contains no characters.

public void
forEachLine(Consumer<? super String> action)

Reads all lines of text from this source, running the given action for each line as it is read.

public boolean
isEmpty()

Returns whether the source has zero chars.

public long
length()

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream.

public Optional<Long>
lengthIfKnown()

Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.

public Stream<String>
lines()

Opens a new Stream for reading text one line at a time from this source.

public BufferedReader
openBufferedStream()

Opens a new BufferedReader for reading from this source.

public abstract Reader
openStream()

Opens a new Reader for reading from this source.

public String
read()

Reads the contents of this source as a string.

public String
readFirstLine()

Reads the first line of this source as a string.

public ImmutableList<String>
readLines()

Reads all the lines of this source as a list of strings.

public <T extends @Nullable Object> T
readLines(LineProcessor<T> processor)

Reads lines of text from this source, processing each line as it is read using the given processor.

public static CharSource
wrap(CharSequence charSequence)

Returns a view of the given character sequence as a CharSource.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CharSourceback to summary
protected CharSource()

Constructor for use by subclasses.

Method Detail

asByteSourceback to summary
public ByteSource asByteSource(Charset charset)

Returns a ByteSource view of this char source that encodes chars read from this source as bytes using the given Charset.

If ByteSource#asCharSource is called on the returned source with the same charset, the default implementation of this method will ensure that the original CharSource is returned, rather than round-trip encoding. Subclasses that override this method should behave the same way.

Since
20.0
concatback to summary
public static CharSource concat(Iterable<? extends CharSource> sources)

Concatenates multiple CharSource instances into a single source. Streams returned from the source will contain the concatenated data from the streams of the underlying sources.

Only one underlying stream will be open at a time. Closing the concatenated stream will close the open underlying stream.

Parameters
sources:Iterable<? extends CharSource>

the sources to concatenate

Returns:CharSource

a CharSource containing the concatenated data

Since
15.0
concatback to summary
public static CharSource concat(Iterator<? extends CharSource> sources)

Concatenates multiple CharSource instances into a single source. Streams returned from the source will contain the concatenated data from the streams of the underlying sources.

Only one underlying stream will be open at a time. Closing the concatenated stream will close the open underlying stream.

Note

The input Iterator will be copied to an ImmutableList when this method is called. This will fail if the iterator is infinite and may cause problems if the iterator eagerly fetches data for each source when iterated (rather than producing sources that only load data through their streams). Prefer using the concat(Iterable) overload if possible.

Parameters
sources:Iterator<? extends CharSource>

the sources to concatenate

Returns:CharSource

a CharSource containing the concatenated data

Exceptions
NullPointerException:
if any of sources is null
Since
15.0
concatback to summary
public static CharSource concat(CharSource... sources)

Concatenates multiple CharSource instances into a single source. Streams returned from the source will contain the concatenated data from the streams of the underlying sources.

Only one underlying stream will be open at a time. Closing the concatenated stream will close the open underlying stream.

Parameters
sources:CharSource[]

the sources to concatenate

Returns:CharSource

a CharSource containing the concatenated data

Exceptions
NullPointerException:
if any of sources is null
Since
15.0
copyToback to summary
public long copyTo(Appendable appendable) throws IOException

Appends the contents of this source to the given Appendable (such as a Writer). Does not close appendable if it is Closeable.

Returns:long

the number of characters copied

Annotations
@CanIgnoreReturnValue
Exceptions
IOException:
if an I/O error occurs while reading from this source or writing to appendable
copyToback to summary
public long copyTo(CharSink sink) throws IOException

Copies the contents of this source to the given sink.

Returns:long

the number of characters copied

Annotations
@CanIgnoreReturnValue
Exceptions
IOException:
if an I/O error occurs while reading from this source or writing to sink
countBySkippingback to summary
private long countBySkipping(Reader reader) throws IOException
emptyback to summary
public static CharSource empty()

Returns an immutable CharSource that contains no characters.

Since
15.0
forEachLineback to summary
public void forEachLine(Consumer<? super String> action) throws IOException

Reads all lines of text from this source, running the given action for each line as it is read.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Exceptions
IOException:
if an I/O error occurs while reading from this source or if action throws an UncheckedIOException
Since
22.0
isEmptyback to summary
public boolean isEmpty() throws IOException

Returns whether the source has zero chars. The default implementation first checks lengthIfKnown, returning true if it's known to be zero and false if it's known to be non-zero. If the length is not known, it falls back to opening a stream and checking for EOF.

Note that, in cases where lengthIfKnown returns zero, it is possible that chars are actually available for reading. This means that a source may return true from isEmpty() despite having readable content.

Exceptions
IOException:
if an I/O error occurs
Since
15.0
lengthback to summary
public long length() throws IOException

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, see lengthIfKnown.

The default implementation calls lengthIfKnown and returns the value if present. If absent, it will fall back to a heavyweight operation that will open a stream, skip to the end of the stream, and return the total number of chars that were skipped.

Note that for sources that implement lengthIfKnown to provide a more efficient implementation, it is possible that this method will return a different number of chars than would be returned by reading all of the chars.

In either case, for mutable sources such as files, a subsequent read may return a different number of chars if the contents are changed.

Exceptions
IOException:
if an I/O error occurs while reading the length of this source
Since
19.0
lengthIfKnownback to summary
public Optional<Long> lengthIfKnown()

Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.

The default implementation returns Optional#absent. Some sources, such as a CharSequence, may return a non-absent value. Note that in such cases, it is possible that this method will return a different number of chars than would be returned by reading all of the chars.

Additionally, for mutable sources such as StringBuilders, a subsequent read may return a different number of chars if the contents are changed.

Since
19.0
linesback to summary
public Stream<String> lines() throws IOException

Opens a new Stream for reading text one line at a time from this source. This method returns a new, independent stream each time it is called.

The returned stream is lazy and only reads from the source in the terminal operation. If an I/O error occurs while the stream is reading from the source or when the stream is closed, an UncheckedIOException is thrown.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

The caller is responsible for ensuring that the returned stream is closed. For example:

try (Stream<String> lines = source.lines()) {
  lines.map(...)
     .filter(...)
     .forEach(...);
}
Annotations
@MustBeClosed
Exceptions
IOException:
if an I/O error occurs while opening the stream
Since
22.0
openBufferedStreamback to summary
public BufferedReader openBufferedStream() throws IOException

Opens a new BufferedReader for reading from this source. This method returns a new, independent reader each time it is called.

The caller is responsible for ensuring that the returned reader is closed.

Exceptions
IOException:
if an I/O error occurs while of opening the reader
openStreamback to summary
public abstract Reader openStream() throws IOException

Opens a new Reader for reading from this source. This method returns a new, independent reader each time it is called.

The caller is responsible for ensuring that the returned reader is closed.

Exceptions
IOException:
if an I/O error occurs while opening the reader
readback to summary
public String read() throws IOException

Reads the contents of this source as a string.

Exceptions
IOException:
if an I/O error occurs while reading from this source
readFirstLineback to summary
public String readFirstLine() throws IOException

Reads the first line of this source as a string. Returns null if this source is empty.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Annotations
@CheckForNull
Exceptions
IOException:
if an I/O error occurs while reading from this source
readLinesback to summary
public ImmutableList<String> readLines() throws IOException

Reads all the lines of this source as a list of strings. The returned list will be empty if this source is empty.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Exceptions
IOException:
if an I/O error occurs while reading from this source
readLinesback to summary
public <T extends @Nullable Object> T readLines(LineProcessor<T> processor) throws IOException

Reads lines of text from this source, processing each line as it is read using the given processor. Stops when all lines have been processed or the processor returns false and returns the result produced by the processor.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Annotations
@CanIgnoreReturnValue
@ParametricNullness
Exceptions
IOException:
if an I/O error occurs while reading from this source or if processor throws an IOException
Since
16.0
wrapback to summary
public static CharSource wrap(CharSequence charSequence)

Returns a view of the given character sequence as a CharSource. The behavior of the returned CharSource and any Reader instances created by it is unspecified if the charSequence is mutated while it is being read, so don't do that.

Since
15.0 (since 14.0 as CharStreams.asCharSource(String))
com.google.common.io back to summary

private final Class CharSource.AsByteSource

extends ByteSource
Class Inheritance

A byte source that reads chars from this source and encodes them as bytes using a charset.

Field Summary

Modifier and TypeField and Description
pack-priv final Charset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public CharSource
asCharSource(Charset charset)

Overrides com.google.common.io.ByteSource.asCharSource.

Returns a CharSource view of this byte source that decodes bytes read from this source as characters using the given Charset.
public InputStream
openStream()

Implements abstract com.google.common.io.ByteSource.openStream.

Opens a new InputStream for reading from this source.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.io.ByteSource:
concatconcatconcatcontentEqualscopyTocopyToemptyhashisEmptyopenBufferedStreamreadreadsizesizeIfKnownslicewrap

Field Detail

charsetback to summary
pack-priv final Charset charset

Constructor Detail

AsByteSourceback to summary
pack-priv AsByteSource(Charset charset)

Method Detail

asCharSourceback to summary
public CharSource asCharSource(Charset charset)

Overrides com.google.common.io.ByteSource.asCharSource.

Doc from com.google.common.io.ByteSource.asCharSource.

Returns a CharSource view of this byte source that decodes bytes read from this source as characters using the given Charset.

If CharSource#asByteSource is called on the returned source with the same charset, the default implementation of this method will ensure that the original ByteSource is returned, rather than round-trip encoding. Subclasses that override this method should behave the same way.

Annotations
@Override
openStreamback to summary
public InputStream openStream() throws IOException

Implements abstract com.google.common.io.ByteSource.openStream.

Doc from com.google.common.io.ByteSource.openStream.

Opens a new InputStream for reading from this source. This method returns a new, independent stream each time it is called.

The caller is responsible for ensuring that the returned stream is closed.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while opening the stream
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.io back to summary

private Class CharSource.CharSequenceCharSource

extends CharSource
Class Inheritance
Known Direct Subclasses
com.google.common.io.CharSource.StringCharSource

Field Summary

Modifier and TypeField and Description
private static final Splitter
protected final CharSequence

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean
isEmpty()

Overrides com.google.common.io.CharSource.isEmpty.

Returns whether the source has zero chars.
public long
length()

Overrides com.google.common.io.CharSource.length.

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream.
public Optional<Long>
lengthIfKnown()

Overrides com.google.common.io.CharSource.lengthIfKnown.

Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.
public Stream<String>
lines()

Overrides com.google.common.io.CharSource.lines.

Opens a new Stream for reading text one line at a time from this source.
private Iterator<String>
linesIterator()

Returns an iterator over the lines in the string.

public Reader
openStream()

Implements abstract com.google.common.io.CharSource.openStream.

Opens a new Reader for reading from this source.
public String
read()

Overrides com.google.common.io.CharSource.read.

Reads the contents of this source as a string.
public String
readFirstLine()

Overrides com.google.common.io.CharSource.readFirstLine.

Reads the first line of this source as a string.
public ImmutableList<String>
readLines()

Overrides com.google.common.io.CharSource.readLines.

Reads all the lines of this source as a list of strings.
public <T extends @Nullable Object> T
readLines(LineProcessor<T> processor)

Overrides com.google.common.io.CharSource.readLines.

Reads lines of text from this source, processing each line as it is read using the given processor.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.io.CharSource:
asByteSourceconcatconcatconcatcopyTocopyToemptyforEachLineopenBufferedStreamwrap

Field Detail

LINE_SPLITTERback to summary
private static final Splitter LINE_SPLITTER
seqback to summary
protected final CharSequence seq

Constructor Detail

CharSequenceCharSourceback to summary
protected CharSequenceCharSource(CharSequence seq)

Method Detail

isEmptyback to summary
public boolean isEmpty()

Overrides com.google.common.io.CharSource.isEmpty.

Doc from com.google.common.io.CharSource.isEmpty.

Returns whether the source has zero chars. The default implementation first checks lengthIfKnown, returning true if it's known to be zero and false if it's known to be non-zero. If the length is not known, it falls back to opening a stream and checking for EOF.

Note that, in cases where lengthIfKnown returns zero, it is possible that chars are actually available for reading. This means that a source may return true from isEmpty() despite having readable content.

Annotations
@Override
lengthback to summary
public long length()

Overrides com.google.common.io.CharSource.length.

Doc from com.google.common.io.CharSource.length.

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, see lengthIfKnown.

The default implementation calls lengthIfKnown and returns the value if present. If absent, it will fall back to a heavyweight operation that will open a stream, skip to the end of the stream, and return the total number of chars that were skipped.

Note that for sources that implement lengthIfKnown to provide a more efficient implementation, it is possible that this method will return a different number of chars than would be returned by reading all of the chars.

In either case, for mutable sources such as files, a subsequent read may return a different number of chars if the contents are changed.

Annotations
@Override
lengthIfKnownback to summary
public Optional<Long> lengthIfKnown()

Overrides com.google.common.io.CharSource.lengthIfKnown.

Doc from com.google.common.io.CharSource.lengthIfKnown.

Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.

The default implementation returns Optional#absent. Some sources, such as a CharSequence, may return a non-absent value. Note that in such cases, it is possible that this method will return a different number of chars than would be returned by reading all of the chars.

Additionally, for mutable sources such as StringBuilders, a subsequent read may return a different number of chars if the contents are changed.

Annotations
@Override
linesback to summary
public Stream<String> lines()

Overrides com.google.common.io.CharSource.lines.

Doc from com.google.common.io.CharSource.lines.

Opens a new Stream for reading text one line at a time from this source. This method returns a new, independent stream each time it is called.

The returned stream is lazy and only reads from the source in the terminal operation. If an I/O error occurs while the stream is reading from the source or when the stream is closed, an UncheckedIOException is thrown.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

The caller is responsible for ensuring that the returned stream is closed. For example:

try (Stream<String> lines = source.lines()) {
  lines.map(...)
     .filter(...)
     .forEach(...);
}
Annotations
@Override
linesIteratorback to summary
private Iterator<String> linesIterator()

Returns an iterator over the lines in the string. If the string ends in a newline, a final empty string is not included, to match the behavior of BufferedReader/LineReader.readLine().

openStreamback to summary
public Reader openStream()

Implements abstract com.google.common.io.CharSource.openStream.

Doc from com.google.common.io.CharSource.openStream.

Opens a new Reader for reading from this source. This method returns a new, independent reader each time it is called.

The caller is responsible for ensuring that the returned reader is closed.

Annotations
@Override
readback to summary
public String read()

Overrides com.google.common.io.CharSource.read.

Doc from com.google.common.io.CharSource.read.

Reads the contents of this source as a string.

Annotations
@Override
readFirstLineback to summary
public String readFirstLine()

Overrides com.google.common.io.CharSource.readFirstLine.

Doc from com.google.common.io.CharSource.readFirstLine.

Reads the first line of this source as a string. Returns null if this source is empty.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Annotations
@Override
@CheckForNull
readLinesback to summary
public ImmutableList<String> readLines()

Overrides com.google.common.io.CharSource.readLines.

Doc from com.google.common.io.CharSource.readLines.

Reads all the lines of this source as a list of strings. The returned list will be empty if this source is empty.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Annotations
@Override
readLinesback to summary
public <T extends @Nullable Object> T readLines(LineProcessor<T> processor) throws IOException

Overrides com.google.common.io.CharSource.readLines.

Doc from com.google.common.io.CharSource.readLines.

Reads lines of text from this source, processing each line as it is read using the given processor. Stops when all lines have been processed or the processor returns false and returns the result produced by the processor.

Like BufferedReader#readLine(), this method considers a line to be a sequence of text that is terminated by (but does not include) one of \r\n, \r or \n. If the source's content does not end in a line termination sequence, it is treated as if it does.

Annotations
@Override
@ParametricNullness
Exceptions
IOException:
if an I/O error occurs while reading from this source or if processor throws an IOException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.io back to summary

private final Class CharSource.ConcatenatedCharSource

extends CharSource
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Iterable<? extends CharSource>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
isEmpty()

Overrides com.google.common.io.CharSource.isEmpty.

Returns whether the source has zero chars.
public long
length()

Overrides com.google.common.io.CharSource.length.

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream.
public Optional<Long>
lengthIfKnown()

Overrides com.google.common.io.CharSource.lengthIfKnown.

Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.
public Reader
openStream()

Implements abstract com.google.common.io.CharSource.openStream.

Opens a new Reader for reading from this source.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.io.CharSource:
asByteSourceconcatconcatconcatcopyTocopyToemptyforEachLinelinesopenBufferedStreamreadreadFirstLinereadLinesreadLineswrap

Field Detail

sourcesback to summary
private final Iterable<? extends CharSource> sources

Constructor Detail

ConcatenatedCharSourceback to summary
pack-priv ConcatenatedCharSource(Iterable<? extends CharSource> sources)

Method Detail

isEmptyback to summary
public boolean isEmpty() throws IOException

Overrides com.google.common.io.CharSource.isEmpty.

Doc from com.google.common.io.CharSource.isEmpty.

Returns whether the source has zero chars. The default implementation first checks lengthIfKnown, returning true if it's known to be zero and false if it's known to be non-zero. If the length is not known, it falls back to opening a stream and checking for EOF.

Note that, in cases where lengthIfKnown returns zero, it is possible that chars are actually available for reading. This means that a source may return true from isEmpty() despite having readable content.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
lengthback to summary
public long length() throws IOException

Overrides com.google.common.io.CharSource.length.

Doc from com.google.common.io.CharSource.length.

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, see lengthIfKnown.

The default implementation calls lengthIfKnown and returns the value if present. If absent, it will fall back to a heavyweight operation that will open a stream, skip to the end of the stream, and return the total number of chars that were skipped.

Note that for sources that implement lengthIfKnown to provide a more efficient implementation, it is possible that this method will return a different number of chars than would be returned by reading all of the chars.

In either case, for mutable sources such as files, a subsequent read may return a different number of chars if the contents are changed.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while reading the length of this source
lengthIfKnownback to summary
public Optional<Long> lengthIfKnown()

Overrides com.google.common.io.CharSource.lengthIfKnown.

Doc from com.google.common.io.CharSource.lengthIfKnown.

Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.

The default implementation returns Optional#absent. Some sources, such as a CharSequence, may return a non-absent value. Note that in such cases, it is possible that this method will return a different number of chars than would be returned by reading all of the chars.

Additionally, for mutable sources such as StringBuilders, a subsequent read may return a different number of chars if the contents are changed.

Annotations
@Override
openStreamback to summary
public Reader openStream() throws IOException

Implements abstract com.google.common.io.CharSource.openStream.

Doc from com.google.common.io.CharSource.openStream.

Opens a new Reader for reading from this source. This method returns a new, independent reader each time it is called.

The caller is responsible for ensuring that the returned reader is closed.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while opening the reader
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.io back to summary

private final Class CharSource.EmptyCharSource

extends StringCharSource
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CharSource.EmptyCharSource

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides com.google.common.io.CharSource.CharSequenceCharSource.toString.

Returns a string representation of the object.
Inherited from com.google.common.io.CharSource.StringCharSource:
copyTocopyToopenStream

Field Detail

INSTANCEback to summary
private static final CharSource.EmptyCharSource INSTANCE

Constructor Detail

EmptyCharSourceback to summary
private EmptyCharSource()

Method Detail

toStringback to summary
public String toString()

Overrides com.google.common.io.CharSource.CharSequenceCharSource.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.io back to summary

private Class CharSource.StringCharSource

extends CharSequenceCharSource
Class Inheritance
Known Direct Subclasses
com.google.common.io.CharSource.EmptyCharSource

Subclass specialized for string instances.

Since Strings are immutable and built into the jdk we can optimize some operations

Field Summary

Inherited from com.google.common.io.CharSource.CharSequenceCharSource:
seq

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public long
copyTo(Appendable appendable)

Overrides com.google.common.io.CharSource.copyTo.

Appends the contents of this source to the given Appendable (such as a Writer).
public long
copyTo(CharSink sink)

Overrides com.google.common.io.CharSource.copyTo.

Copies the contents of this source to the given sink.
public Reader
openStream()

Overrides com.google.common.io.CharSource.CharSequenceCharSource.openStream.

Opens a new Reader for reading from this source.
Inherited from com.google.common.io.CharSource.CharSequenceCharSource:
isEmptylengthlengthIfKnownlinesreadreadFirstLinereadLinesreadLinestoString

Constructor Detail

StringCharSourceback to summary
protected StringCharSource(String seq)

Method Detail

copyToback to summary
public long copyTo(Appendable appendable) throws IOException

Overrides com.google.common.io.CharSource.copyTo.

Doc from com.google.common.io.CharSource.copyTo.

Appends the contents of this source to the given Appendable (such as a Writer). Does not close appendable if it is Closeable.

Returns:long

the number of characters copied

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while reading from this source or writing to appendable
copyToback to summary
public long copyTo(CharSink sink) throws IOException

Overrides com.google.common.io.CharSource.copyTo.

Doc from com.google.common.io.CharSource.copyTo.

Copies the contents of this source to the given sink.

Returns:long

the number of characters copied

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while reading from this source or writing to sink
openStreamback to summary
public Reader openStream()

Overrides com.google.common.io.CharSource.CharSequenceCharSource.openStream.

Doc from com.google.common.io.CharSource.openStream.

Opens a new Reader for reading from this source. This method returns a new, independent reader each time it is called.

The caller is responsible for ensuring that the returned reader is closed.

Annotations
@Override