Package org.apache.sis.io
Class Appender
java.lang.Object
org.apache.sis.io.Appender
- All Implemented Interfaces:
Appendable
- Direct Known Subclasses:
LineAppender
,TableAppender
Base class for writing filtered characters to another
Appendable
.
This base class performs a work similar to the FilterWriter
work,
except for the following:
- The filtered output is sent to an arbitrary
Appendable
instead of to theWriter
sub-type. - No synchronization is performed.
Appender
can be viewed as a synchronized
Writer
by invoking the IO.asWriter(Appendable)
method.
Flushing and closing the stream
Subclasses implement theFlushable
interface only if they
hold data in an internal buffer before to send them to the wrapped Appendable
.
This is the case of TableAppender
and LineAppender
for instance.
For unconditionally flushing or closing an Appendable
and its underlying stream,
see IO.flush(Appendable)
and IO.close(Appendable)
.- Since:
- 0.3
- Version:
- 0.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate char
If the last character given totoCodePoint(char)
if it was a high surrogate, or 0 otherwise.protected final Appendable
The underlying character output stream or buffer. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Appender
(Appendable out) Creates a new appender which will send its output to the given stream or buffer. -
Method Summary
Modifier and TypeMethodDescriptionappend
(CharSequence sequence) Appends the specified character sequence.(package private) final void
appendCodePoint
(int c) Appends the given code point to the underlyingout
stream or buffer.(package private) final int
appendSurrogate
(CharSequence sequence, int start, int end) If the given sequence begins with a low surrogate completing a previous high surrogate, delegates toAppendable.append(char)
and returnsstart+1
.(package private) final boolean
(package private) final String
lineSeparator
(CharSequence sequence, int start, int end) Finds the line separator used in the given character sequence portion, or returnsnull
if unknown.(package private) final int
toCodePoint
(char c) Returns the code point for the given character, or -1 if we need to wait for the next character.toString()
Returns the content of thisAppendable
as a string if possible, or the localized "Unavailable content" string otherwise.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Appendable
append, append
-
Field Details
-
out
The underlying character output stream or buffer. -
highSurrogate
private char highSurrogateIf the last character given totoCodePoint(char)
if it was a high surrogate, or 0 otherwise.
-
-
Constructor Details
-
Appender
Creates a new appender which will send its output to the given stream or buffer.- Parameters:
out
- the underlying character output stream or buffer.
-
-
Method Details
-
lineSeparator
Finds the line separator used in the given character sequence portion, or returnsnull
if unknown. This method is designed for invocation at the beginning ofappend(CharSequence, ...)
, before the characters are effectively read. -
toCodePoint
final int toCodePoint(char c) Returns the code point for the given character, or -1 if we need to wait for the next character. This method computes the code point from the given character and the character given to the previous call of this method. This works only if this method is consistently invoked for every characters. -
isHighSurrogate
final boolean isHighSurrogate() -
appendSurrogate
If the given sequence begins with a low surrogate completing a previous high surrogate, delegates toAppendable.append(char)
and returnsstart+1
. The intent is to avoid processing a character sequence which starts by an invalid code point.- Parameters:
sequence
- the character sequence to write.start
- index of the first character to write by this method or by the caller.end
- index after the last character to be written by the caller.- Returns:
- index of the first character which need to be written by the caller.
- Throws:
IOException
-
appendCodePoint
Appends the given code point to the underlyingout
stream or buffer.- Parameters:
c
- the code point to append.- Throws:
IOException
- if an error occurred while appending the code point.
-
append
Appends the specified character sequence. The default implementation delegates toAppendable.append(CharSequence, int, int)
.- Specified by:
append
in interfaceAppendable
- Parameters:
sequence
- the character sequence to append, ornull
.- Returns:
- a reference to this
Appendable
. - Throws:
IOException
- if an I/O error occurred.
-
toString
Returns the content of thisAppendable
as a string if possible, or the localized "Unavailable content" string otherwise.
-