Class Appender

java.lang.Object
org.apache.sis.io.Appender
All Implemented Interfaces:
Appendable
Direct Known Subclasses:
LineAppender, TableAppender

abstract class Appender extends Object implements Appendable
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 the Writer sub-type.
  • No synchronization is performed.
If needed, this Appender can be viewed as a synchronized Writer by invoking the IO.asWriter(Appendable) method.

Flushing and closing the stream

Subclasses implement the Flushable 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

    Fields
    Modifier and Type
    Field
    Description
    private char
    If the last character given to toCodePoint(char) if it was a high surrogate, or 0 otherwise.
    protected final Appendable
    The underlying character output stream or buffer.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new appender which will send its output to the given stream or buffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(CharSequence sequence)
    Appends the specified character sequence.
    (package private) final void
    Appends the given code point to the underlying out 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 to Appendable.append(char) and returns start+1.
    (package private) final boolean
    Returns true if the last character given to toCodePoint(char) is a high surrogate.
    (package private) final String
    lineSeparator(CharSequence sequence, int start, int end)
    Finds the line separator used in the given character sequence portion, or returns null 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.
    Returns the content of this Appendable 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

      protected final Appendable out
      The underlying character output stream or buffer.
    • highSurrogate

      private char highSurrogate
      If the last character given to toCodePoint(char) if it was a high surrogate, or 0 otherwise.
  • Constructor Details

    • Appender

      protected Appender(Appendable out)
      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

      final String lineSeparator(CharSequence sequence, int start, int end)
      Finds the line separator used in the given character sequence portion, or returns null if unknown. This method is designed for invocation at the beginning of append(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()
      Returns true if the last character given to toCodePoint(char) is a high surrogate.
    • appendSurrogate

      final int appendSurrogate(CharSequence sequence, int start, int end) throws IOException
      If the given sequence begins with a low surrogate completing a previous high surrogate, delegates to Appendable.append(char) and returns start+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

      final void appendCodePoint(int c) throws IOException
      Appends the given code point to the underlying out stream or buffer.
      Parameters:
      c - the code point to append.
      Throws:
      IOException - if an error occurred while appending the code point.
    • append

      public Appendable append(CharSequence sequence) throws IOException
      Appends the specified character sequence. The default implementation delegates to Appendable.append(CharSequence, int, int).
      Specified by:
      append in interface Appendable
      Parameters:
      sequence - the character sequence to append, or null.
      Returns:
      a reference to this Appendable.
      Throws:
      IOException - if an I/O error occurred.
    • toString

      public String toString()
      Returns the content of this Appendable as a string if possible, or the localized "Unavailable content" string otherwise.
      Overrides:
      toString in class Object
      Returns:
      the content of this Appendable, or a localized message for unavailable content.
      See Also: