Modifier and Type | Method and Description |
---|---|
static Writer |
asWriter(Appendable out)
Returns a view of the given
Appendable as a Writer . |
static void |
close(Appendable out)
|
static CharSequence |
content(Appendable out)
If the given
out argument implements CharSequence , or is a
chain of wrappers defined in this package around a CharSequence ,
returns that character sequence. |
static void |
flush(Appendable out)
|
public static void flush(Appendable out) throws IOException
out
argument implements Flushable
, or is a chain
of wrappers defined in this package around a flushable object, invokes the
flush()
method on that object. Otherwise do nothing.
Chains of wrappers are followed until a Flushable
instance is found, if any.
The search stops at the first occurrence found.
out
- the output stream, writer or buffer to flush, or null
.IOException
- if an error occurred while flushing the given stream.public static void close(Appendable out) throws IOException
out
argument implements Closeable
, or is a chain
of wrappers defined in this package around a closeable object, invokes the
close()
method on that object. Otherwise do nothing.
Chains of wrappers are followed until a Closeable
instance is found, if any.
The first Flushable
instance found before the Closeable
one,
if any, is flushed.
The search stops at the first Closeable
occurrence found.
out
- the output stream, writer or buffer to close, or null
.IOException
- if an error occurred while closing the given stream.public static CharSequence content(Appendable out)
out
argument implements CharSequence
, or is a
chain of wrappers defined in this package around a CharSequence
,
returns that character sequence. Otherwise returns null
.
Special cases:
Appendable
is a StringWriter
instance, then
its underlying buffer is returned.Appendable
is a CharArrayWriter
instance, then its content
is returned as a string.
This method is useful for getting the result of an Appendable
which wrote,
directly or indirectly, into a StringBuilder
or similar kind of character buffer.
Note that this method returns the underlying buffer if possible; callers should not change
CharSequence
content, unless the Appendable
is not used anymore after this
method call.
It may be necessary to invoke flush(Appendable)
before this method in order
to get proper content. In particular, this is necessary if the chain of Appendable
s
contains TableAppender
or LineAppender
instances.
out
- the output stream, writer or buffer from which to get the content, or null
.null
if unavailable.flush(Appendable)
public static Writer asWriter(Appendable out)
Appendable
as a Writer
.
If the given argument is already a Writer
instance, then it is returned unchanged.
Otherwise if the argument is non-null, then it is wrapped in an adapter.
Any write operations performed on the returned writer will be forwarded
to the given Appendable
.out
- the output stream, writer or buffer to view as a Writer
, or null
.Appendable
as a writer, or null
if the given argument was null.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.