private static final class CharSource.ConcatenatedCharSource extends CharSource
Modifier and Type | Field and Description |
---|---|
private java.lang.Iterable<? extends CharSource> |
sources |
Constructor and Description |
---|
ConcatenatedCharSource(java.lang.Iterable<? extends CharSource> sources) |
Modifier and Type | Method and Description |
---|---|
boolean |
isEmpty()
Returns whether the source has zero chars.
|
long |
length()
Returns the length of this source in chars, even if doing so requires opening and traversing an
entire stream.
|
Optional<java.lang.Long> |
lengthIfKnown()
Returns the size of this source in chars, if the size can be easily determined without actually
opening the data stream.
|
java.io.Reader |
openStream()
Opens a new
Reader for reading from this source. |
java.lang.String |
toString() |
asByteSource, concat, concat, concat, copyTo, copyTo, empty, openBufferedStream, read, readFirstLine, readLines, readLines, wrap
private final java.lang.Iterable<? extends CharSource> sources
ConcatenatedCharSource(java.lang.Iterable<? extends CharSource> sources)
public java.io.Reader openStream() throws java.io.IOException
CharSource
Reader
for reading from this source. This method should return a new,
independent reader each time it is called.
The caller is responsible for ensuring that the returned reader is closed.
openStream
in class CharSource
java.io.IOException
- if an I/O error occurs in the process of opening the readerpublic boolean isEmpty() throws java.io.IOException
CharSource
CharSource.lengthIfKnown()
returns zero, falling back to opening a stream and checking for EOF if
the length is not known.
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.
isEmpty
in class CharSource
java.io.IOException
- if an I/O error occurspublic Optional<java.lang.Long> lengthIfKnown()
CharSource
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 StringBuilder
s, a subsequent read may
return a different number of chars if the contents are changed.
lengthIfKnown
in class CharSource
public long length() throws java.io.IOException
CharSource
CharSource.lengthIfKnown()
.
The default implementation calls CharSource.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 CharSource.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.
length
in class CharSource
java.io.IOException
- if an I/O error occurs in the process of reading the length of this sourcepublic java.lang.String toString()
toString
in class java.lang.Object