Appendable objects.- Since:
- 0.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic WriterasWriter(Appendable out) Returns a view of the givenAppendableas aWriter.static voidclose(Appendable out) static CharSequencecontent(Appendable out) If the givenoutargument implementsCharSequence, or is a chain of wrappers defined in this package around aCharSequence, returns that character sequence.static voidflush(Appendable out)
-
Method Details
-
flush
If the givenoutargument 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
Flushableinstance 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 givenoutargument 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
Closeableinstance is found, if any. The firstFlushableinstance found before theCloseableone, if any, is flushed. The search stops at the firstCloseableoccurrence 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 givenoutargument implementsCharSequence, or is a chain of wrappers defined in this package around aCharSequence, returns that character sequence. Otherwise returnsnull.Special cases:
- If an
Appendableis aStringWriterinstance, then its underlying buffer is returned. - If an
Appendableis aCharArrayWriterinstance, then its content is returned as a string.
This method is useful for getting the result of an
Appendablewhich wrote, directly or indirectly, into aStringBuilderor similar kind of character buffer. Note that this method returns the underlying buffer if possible; callers should not changeCharSequencecontent, unless theAppendableis 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 ofAppendables containsTableAppenderorLineAppenderinstances.- 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
nullif unavailable. - See Also:
- If an
-
asWriter
Returns a view of the givenAppendableas aWriter. If the given argument is already aWriterinstance, 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
Appendableas a writer, ornullif the given argument was null.
-