public abstract class CharSink extends java.lang.Object implements OutputSupplier<java.io.Writer>
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.
Constructor and Description |
---|
CharSink() |
Modifier and Type | Method and Description |
---|---|
java.io.Writer |
getOutput()
Deprecated.
This method is only provided for temporary compatibility with the
OutputSupplier interface and should not be called directly. Use
openStream() instead. |
java.io.Writer |
openBufferedStream()
Opens a new buffered
Writer for writing to this sink. |
abstract java.io.Writer |
openStream()
Opens a new
Writer for writing to this sink. |
void |
write(java.lang.CharSequence charSequence)
Writes the given character sequence to this sink.
|
long |
writeFrom(java.lang.Readable readable)
Writes all the text from the given
Readable (such as a Reader ) to this sink. |
void |
writeLines(java.lang.Iterable<? extends java.lang.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(java.lang.Iterable<? extends java.lang.CharSequence> lines,
java.lang.String lineSeparator)
Writes the given lines of text to this sink with each line (including the last) terminated with
the given line separator.
|
public abstract java.io.Writer openStream() throws java.io.IOException
Writer
for writing to this sink. This method should return a new,
independent writer each time it is called.
The caller is responsible for ensuring that the returned writer is closed.
java.io.IOException
- if an I/O error occurs in the process of opening the writer@Deprecated public final java.io.Writer getOutput() throws java.io.IOException
OutputSupplier
interface and should not be called directly. Use
openStream()
instead.getOutput
in interface OutputSupplier<java.io.Writer>
java.io.IOException
public java.io.Writer openBufferedStream() throws java.io.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 should return a new, independent writer each time it is
called.
The caller is responsible for ensuring that the returned writer is closed.
java.io.IOException
- if an I/O error occurs in the process of opening the writerBufferedWriter
)public void write(java.lang.CharSequence charSequence) throws java.io.IOException
java.io.IOException
- if an I/O error in the process of writing to this sinkpublic void writeLines(java.lang.Iterable<? extends java.lang.CharSequence> lines) throws java.io.IOException
writeLines(lines, System.getProperty("line.separator"))
.java.io.IOException
- if an I/O error occurs in the process of writing to this sinkpublic void writeLines(java.lang.Iterable<? extends java.lang.CharSequence> lines, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
- if an I/O error occurs in the process of writing to this sinkpublic long writeFrom(java.lang.Readable readable) throws java.io.IOException
Readable
(such as a Reader
) to this sink.
Does not close readable
if it is Closeable
.java.io.IOException
- if an I/O error occurs in the process of reading from readable
or
writing to this sinkCopyright © 2010 - 2019 Adobe. All Rights Reserved