Class CharSource.ConcatenatedCharSource
- Enclosing class:
CharSource
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEmpty()Returns whether the source has zero chars.longlength()Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream.Returns the size of this source in chars, if the size can be easily determined without actually opening the data stream.Opens a newReaderfor reading from this source.toString()Methods inherited from class com.google.common.io.CharSource
asByteSource, concat, concat, concat, copyTo, copyTo, empty, forEachLine, lines, openBufferedStream, read, readFirstLine, readLines, readLines, wrap
-
Field Details
-
sources
-
-
Constructor Details
-
ConcatenatedCharSource
ConcatenatedCharSource(Iterable<? extends CharSource> sources)
-
-
Method Details
-
openStream
Description copied from class:CharSourceOpens a newReaderfor 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.
- Specified by:
openStreamin classCharSource- Throws:
IOException- if an I/O error occurs while opening the reader
-
isEmpty
Description copied from class:CharSourceReturns whether the source has zero chars. The default implementation first checksCharSource.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
lengthIfKnownreturns zero, it is possible that chars are actually available for reading. This means that a source may returntruefromisEmpty()despite having readable content.- Overrides:
isEmptyin classCharSource- Throws:
IOException- if an I/O error occurs
-
lengthIfKnown
Description copied from class:CharSourceReturns 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 aCharSequence, 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.- Overrides:
lengthIfKnownin classCharSource
-
length
Description copied from class:CharSourceReturns the length of this source in chars, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, seeCharSource.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,skipto 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.
- Overrides:
lengthin classCharSource- Throws:
IOException- if an I/O error occurs while reading the length of this source
-
toString
-