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
StringReaderinstead 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 TypeMethodDescriptionlongCopies the contents of this source to the given sink.longcopyTo(Appendable appendable) Appends the contents of this source to the givenAppendable(such as aWriter).Opens a newReaderfor reading from this source.Methods inherited from class com.google.common.io.CharSource.CharSequenceCharSource
isEmpty, length, lengthIfKnown, lines, read, readFirstLine, readLines, readLines, toStringMethods 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: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.
- Overrides:
openStreamin classCharSource.CharSequenceCharSource
-
copyTo
Description copied from class:CharSourceAppends the contents of this source to the givenAppendable(such as aWriter). Does not closeappendableif it isCloseable.- Overrides:
copyToin 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:CharSourceCopies the contents of this source to the given sink.- Overrides:
copyToin classCharSource- Returns:
- the number of characters copied
- Throws:
IOException- if an I/O error occurs while reading from this source or writing tosink
-