Appendable
objects.- Since:
- 0.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic Writer
asWriter
(Appendable out) Returns a view of the givenAppendable
as aWriter
.static void
close
(Appendable out) static CharSequence
content
(Appendable out) If the givenout
argument implementsCharSequence
, or is a chain of wrappers defined in this package around aCharSequence
, returns that character sequence.static void
flush
(Appendable out)
-
Method Details
-
flush
If the givenout
argument implementsFlushable
, or is a chain of wrappers defined in this package around a flushable object, invokes theflush()
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.- Parameters:
out
- the output stream, writer or buffer to flush, ornull
.- Throws:
IOException
- if an error occurred while flushing the given stream.
-
close
If the givenout
argument implementsCloseable
, or is a chain of wrappers defined in this package around a closeable object, invokes theclose()
method on that object. Otherwise do nothing.Chains of wrappers are followed until a
Closeable
instance is found, if any. The firstFlushable
instance found before theCloseable
one, if any, is flushed. The search stops at the firstCloseable
occurrence found.- Parameters:
out
- the output stream, writer or buffer to close, ornull
.- Throws:
IOException
- if an error occurred while closing the given stream.
-
content
If the givenout
argument implementsCharSequence
, or is a chain of wrappers defined in this package around aCharSequence
, returns that character sequence. Otherwise returnsnull
.Special cases:
- If an
Appendable
is aStringWriter
instance, then its underlying buffer is returned. - If an
Appendable
is aCharArrayWriter
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 aStringBuilder
or similar kind of character buffer. Note that this method returns the underlying buffer if possible; callers should not changeCharSequence
content, unless theAppendable
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 ofAppendable
s containsTableAppender
orLineAppender
instances.- Parameters:
out
- the output stream, writer or buffer from which to get the content, ornull
.- Returns:
- the content of the given stream of buffer, or
null
if unavailable. - See Also:
- If an
-
asWriter
Returns a view of the givenAppendable
as aWriter
. If the given argument is already aWriter
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 givenAppendable
.- Parameters:
out
- the output stream, writer or buffer to view as aWriter
, ornull
.- Returns:
- a view of this
Appendable
as a writer, ornull
if the given argument was null.
-