Package com.google.common.io
Class CharSource.StringCharSource
java.lang.Object
com.google.common.io.CharSource
com.google.common.io.CharSource.CharSequenceCharSource
com.google.common.io.CharSource.StringCharSource
- Direct Known Subclasses:
CharSource.EmptyCharSource
- Enclosing class:
CharSource
Subclass specialized for string instances.
Since Strings are immutable and built into the jdk we can optimize some operations
- use
StringReader
instead ofCharSequenceReader
. It is faster since it can useString.getChars(int, int, char[], int)
instead of copying characters one by one withCharSequence.charAt(int)
. - use
Appendable.append(CharSequence)
incopyTo(Appendable)
andcopyTo(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.
-
Field Summary
Fields inherited from class com.google.common.io.CharSource.CharSequenceCharSource
seq
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Copies the contents of this source to the given sink.long
copyTo
(Appendable appendable) Appends the contents of this source to the givenAppendable
(such as aWriter
).Opens a newReader
for reading from this source.Methods inherited from class com.google.common.io.CharSource.CharSequenceCharSource
isEmpty, length, lengthIfKnown, lines, read, readFirstLine, readLines, readLines, toString
Methods inherited from class com.google.common.io.CharSource
asByteSource, concat, concat, concat, empty, forEachLine, openBufferedStream, wrap
-
Constructor Details
-
StringCharSource
-
-
Method Details
-
openStream
Description copied from class:CharSource
Opens a newReader
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.
- Overrides:
openStream
in classCharSource.CharSequenceCharSource
-
copyTo
Description copied from class:CharSource
Appends the contents of this source to the givenAppendable
(such as aWriter
). Does not closeappendable
if it isCloseable
.- Overrides:
copyTo
in classCharSource
- Returns:
- the number of characters copied
- Throws:
IOException
- if an I/O error occurs while reading from this source or writing toappendable
-
copyTo
Description copied from class:CharSource
Copies the contents of this source to the given sink.- Overrides:
copyTo
in classCharSource
- Returns:
- the number of characters copied
- Throws:
IOException
- if an I/O error occurs while reading from this source or writing tosink
-