Package com.google.common.io
Class ByteSource.AsCharSource
- java.lang.Object
-
- com.google.common.io.CharSource
-
- com.google.common.io.ByteSource.AsCharSource
-
- Enclosing class:
- ByteSource
class ByteSource.AsCharSource extends CharSource
A char source that reads bytes from this source and decodes them as characters using a charset.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.nio.charset.Charset
charset
-
Constructor Summary
Constructors Constructor Description AsCharSource(java.nio.charset.Charset charset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteSource
asByteSource(java.nio.charset.Charset charset)
Returns aByteSource
view of this char source that encodes chars read from this source as bytes using the givenCharset
.java.io.Reader
openStream()
Opens a newReader
for reading from this source.java.lang.String
read()
Reads the contents of this source as a string.java.lang.String
toString()
-
Methods inherited from class com.google.common.io.CharSource
concat, concat, concat, copyTo, copyTo, empty, forEachLine, isEmpty, length, lengthIfKnown, lines, openBufferedStream, readFirstLine, readLines, readLines, wrap
-
-
-
-
Method Detail
-
asByteSource
public ByteSource asByteSource(java.nio.charset.Charset charset)
Description copied from class:CharSource
Returns aByteSource
view of this char source that encodes chars read from this source as bytes using the givenCharset
.If
ByteSource.asCharSource(java.nio.charset.Charset)
is called on the returned source with the same charset, the default implementation of this method will ensure that the originalCharSource
is returned, rather than round-trip encoding. Subclasses that override this method should behave the same way.- Overrides:
asByteSource
in classCharSource
-
openStream
public java.io.Reader openStream() throws java.io.IOException
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.
- Specified by:
openStream
in classCharSource
- Throws:
java.io.IOException
- if an I/O error occurs while opening the reader
-
read
public java.lang.String read() throws java.io.IOException
Description copied from class:CharSource
Reads the contents of this source as a string.- Overrides:
read
in classCharSource
- Throws:
java.io.IOException
- if an I/O error occurs while reading from this source
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-