com.univocity.parsers.common.input
Class WriterCharAppender

java.lang.Object
  extended by com.univocity.parsers.common.input.DefaultCharAppender
      extended by com.univocity.parsers.common.input.ExpandingCharAppender
          extended by com.univocity.parsers.common.input.WriterCharAppender
All Implemented Interfaces:
CharAppender, CharSequence

public class WriterCharAppender
extends ExpandingCharAppender

Extension of the DefaultCharAppender class to include facilities for writing to an output. Used by writers extending AbstractWriter.

This class introduces the handling of the normalized newline character defined in Format.getNormalizedNewline() and converts it to the newline sequence in Format.getLineSeparator()

It also introduces methods to write to an instance of Writer directly to avoid unnecessary String instantiations.

Author:
uniVocity Software Pty Ltd - parsers@univocity.com
See Also:
Format, AbstractWriter

Constructor Summary
WriterCharAppender(int maxLength, String emptyValue, Format format)
          Creates a WriterCharAppender with: a maximum limit of characters to append the default value to return when no characters have been accumulated. the basic Format specification for handling newlines The padding character is defaulted to a whitespace character ' '.
 
Method Summary
 void append(char ch)
          Appends the given character.
 void appendIgnoringPadding(char ch, char padding)
          Appends the given character and marks it as ignored if it is a padding character
 void appendIgnoringWhitespace(char ch)
          Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ')
 void appendIgnoringWhitespaceAndPadding(char ch, char padding)
          Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ') or a padding character
 void appendNewLine()
          Appends the newline character sequence specified in Format.getLineSeparator()
 void enableDenormalizedLineEndings(boolean enableDenormalizedLineEndings)
          Configures the appender to allow line ending sequences to be appended as-is, without replacing them by the normalized line separator character.
 void writeCharsAndReset(Writer writer)
          Writes the accumulated value to the Writer, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
 
Methods inherited from class com.univocity.parsers.common.input.ExpandingCharAppender
append, append, append, appendUntil, appendUntil, appendUntil, fill, prepend, prepend
 
Methods inherited from class com.univocity.parsers.common.input.DefaultCharAppender
append, append, charAt, getAndReset, getChars, getCharsAndReset, length, reset, resetWhitespaceCount, subSequence, toString, updateWhitespace, whitespaceCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WriterCharAppender

public WriterCharAppender(int maxLength,
                          String emptyValue,
                          Format format)
Creates a WriterCharAppender with: The padding character is defaulted to a whitespace character ' '.

Parameters:
maxLength - maximum limit of characters to append
emptyValue - default value to return when no characters have been accumulated
format - output format specification used for newline handling
Method Detail

appendIgnoringWhitespace

public final void appendIgnoringWhitespace(char ch)
Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ')

If the given character is equal to Format.getNormalizedNewline(), then the character sequence returned by Format.getLineSeparator() is going to be appended.

Specified by:
appendIgnoringWhitespace in interface CharAppender
Overrides:
appendIgnoringWhitespace in class ExpandingCharAppender
Parameters:
ch - character to append

appendIgnoringPadding

public final void appendIgnoringPadding(char ch,
                                        char padding)
Appends the given character and marks it as ignored if it is a padding character

If the given character is equal to Format.getNormalizedNewline(), then the character sequence returned by Format.getLineSeparator() is going to be appended.

Specified by:
appendIgnoringPadding in interface CharAppender
Overrides:
appendIgnoringPadding in class ExpandingCharAppender
Parameters:
ch - character to append
padding - the padding character

appendIgnoringWhitespaceAndPadding

public final void appendIgnoringWhitespaceAndPadding(char ch,
                                                     char padding)
Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ') or a padding character

If the given character is equal to Format.getNormalizedNewline(), then the character sequence returned by Format.getLineSeparator() is going to be appended.

Specified by:
appendIgnoringWhitespaceAndPadding in interface CharAppender
Overrides:
appendIgnoringWhitespaceAndPadding in class ExpandingCharAppender
Parameters:
ch - character to append
padding - the padding character

append

public final void append(char ch)
Appends the given character.

If the given character is equal to Format.getNormalizedNewline(), then the character sequence returned by Format.getLineSeparator() is going to be appended.

Specified by:
append in interface CharAppender
Overrides:
append in class ExpandingCharAppender
Parameters:
ch - the character to append

writeCharsAndReset

public final void writeCharsAndReset(Writer writer)
                              throws IOException
Writes the accumulated value to the Writer, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)

The internal accumulated value is discarded after invoking this method (as in DefaultCharAppender.reset())

If the accumulated value is empty (i.e. no characters were appended, or all appended characters where ignored as whitespace or padding), then the written value will be the DefaultCharAppender.emptyValue attribute defined in the constructor of this class.

Parameters:
writer - the output writer
Throws:
IOException - if an error occurs while writing to the output.

appendNewLine

public final void appendNewLine()
Appends the newline character sequence specified in Format.getLineSeparator()


enableDenormalizedLineEndings

public final void enableDenormalizedLineEndings(boolean enableDenormalizedLineEndings)
Configures the appender to allow line ending sequences to be appended as-is, without replacing them by the normalized line separator character.

Parameters:
enableDenormalizedLineEndings - flag indicating whether denormalized line endings are allowed. The writer won't convert line separators automatically.


Copyright © 2016 uniVocity Software Pty Ltd. All rights reserved.