@GwtIncompatible public abstract class CharSink extends Object
Writer
, a
CharSink
is not an open, stateful stream that can be written to and closed. Instead, it
is an immutable supplier of Writer
instances.
CharSink
provides two kinds of methods:
Any ByteSink
may be viewed as a CharSink
with a specific character encoding using ByteSink.asCharSink(Charset)
. Characters written to the
resulting CharSink
will written to the ByteSink
as encoded bytes.
Modifier | Constructor and Description |
---|---|
protected |
CharSink()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
Writer |
openBufferedStream()
Opens a new buffered
Writer for writing to this sink. |
abstract Writer |
openStream()
Opens a new
Writer for writing to this sink. |
void |
write(CharSequence charSequence)
Writes the given character sequence to this sink.
|
long |
writeFrom(Readable readable)
|
void |
writeLines(Iterable<? extends CharSequence> lines)
Writes the given lines of text to this sink with each line (including the last) terminated with
the operating system's default line separator.
|
void |
writeLines(Iterable<? extends CharSequence> lines,
String lineSeparator)
Writes the given lines of text to this sink with each line (including the last) terminated with
the given line separator.
|
void |
writeLines(Stream<? extends CharSequence> lines)
Writes the given lines of text to this sink with each line (including the last) terminated with
the operating system's default line separator.
|
void |
writeLines(Stream<? extends CharSequence> lines,
String lineSeparator)
Writes the given lines of text to this sink with each line (including the last) terminated with
the given line separator.
|
protected CharSink()
public abstract Writer openStream() throws IOException
Writer
for writing to this sink. This method returns a new, independent
writer each time it is called.
The caller is responsible for ensuring that the returned writer is closed.
IOException
- if an I/O error occurs while opening the writerpublic Writer openBufferedStream() throws IOException
Writer
for writing to this sink. The returned stream is not
required to be a BufferedWriter
in order to allow implementations to simply delegate to
openStream()
when the stream returned by that method does not benefit from additional
buffering. This method returns a new, independent writer each time it is called.
The caller is responsible for ensuring that the returned writer is closed.
IOException
- if an I/O error occurs while opening the writerBufferedWriter
)public void write(CharSequence charSequence) throws IOException
IOException
- if an I/O error while writing to this sinkpublic void writeLines(Iterable<? extends CharSequence> lines) throws IOException
writeLines(lines, System.getProperty("line.separator"))
.IOException
- if an I/O error occurs while writing to this sinkpublic void writeLines(Iterable<? extends CharSequence> lines, String lineSeparator) throws IOException
IOException
- if an I/O error occurs while writing to this sink@Beta public void writeLines(Stream<? extends CharSequence> lines) throws IOException
writeLines(lines, System.getProperty("line.separator"))
.IOException
- if an I/O error occurs while writing to this sink@Beta public void writeLines(Stream<? extends CharSequence> lines, String lineSeparator) throws IOException
IOException
- if an I/O error occurs while writing to this sinkpublic long writeFrom(Readable readable) throws IOException
Readable
(such as a Reader
) to this sink.
Does not close readable
if it is Closeable
.IOException
- if an I/O error occurs while reading from readable
or writing to
this sinkCopyright © 2010-2017. All Rights Reserved.