private static class CharSource.StringCharSource extends CharSource.CharSequenceCharSource
Since Strings are immutable and built into the jdk we can optimize some operations
StringReader instead of CharSequenceReader. It is faster since it can
use String.getChars(int, int, char[], int) instead of copying characters one by
one with CharSequence.charAt(int).
Appendable.append(CharSequence) in copyTo(Appendable) and copyTo(CharSink). We know this is correct since strings are immutable and so the length
can't change, and it is faster because many writers and appendables are optimized for
appending string instances.
seq| Modifier | Constructor and Description |
|---|---|
protected |
StringCharSource(java.lang.String seq) |
| Modifier and Type | Method and Description |
|---|---|
long |
copyTo(java.lang.Appendable appendable)
Appends the contents of this source to the given
Appendable (such as a Writer). |
long |
copyTo(CharSink sink)
Copies the contents of this source to the given sink.
|
java.io.Reader |
openStream()
Opens a new
Reader for reading from this source. |
isEmpty, length, lengthIfKnown, lines, read, readFirstLine, readLines, readLines, toStringasByteSource, concat, concat, concat, empty, forEachLine, openBufferedStream, wrappublic java.io.Reader openStream()
CharSourceReader 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.
openStream in class CharSource.CharSequenceCharSourcepublic long copyTo(java.lang.Appendable appendable)
throws java.io.IOException
CharSourceAppendable (such as a Writer).
Does not close appendable if it is Closeable.copyTo in class CharSourcejava.io.IOException - if an I/O error occurs while reading from this source or writing to appendablepublic long copyTo(CharSink sink) throws java.io.IOException
CharSourcecopyTo in class CharSourcejava.io.IOException - if an I/O error occurs while reading from this source or writing to sink