Class WriterCharAppender
- java.lang.Object
-
- com.univocity.parsers.common.input.DefaultCharAppender
-
- com.univocity.parsers.common.input.ExpandingCharAppender
-
- com.univocity.parsers.common.input.WriterCharAppender
-
- All Implemented Interfaces:
CharAppender
,java.lang.CharSequence
public class WriterCharAppender extends ExpandingCharAppender
Extension of theDefaultCharAppender
class to include facilities for writing to an output. Used by writers extendingAbstractWriter
.This class introduces the handling of the normalized newline character defined in
Format.getNormalizedNewline()
and converts it to the newline sequence inFormat.getLineSeparator()
It also introduces methods to write to an instance of
Writer
directly to avoid unnecessary String instantiations.- See Also:
Format
,AbstractWriter
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
denormalizeLineEndings
private char
lineSeparator1
private char
lineSeparator2
private char
newLine
-
Fields inherited from class com.univocity.parsers.common.input.DefaultCharAppender
chars, emptyChars, emptyValue, index, whitespaceCount, whitespaceRangeStart
-
-
Constructor Summary
Constructors Constructor Description WriterCharAppender(int maxLength, java.lang.String emptyValue, int whitespaceRangeStart, 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 basicFormat
specification for handling newlines The padding character is defaulted to a whitespace character ' '.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 charactervoid
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 charactervoid
appendNewLine()
Appends the newline character sequence specified inFormat.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(java.io.Writer writer)
Writes the accumulated value to theWriter
, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char)
,appendIgnoringPadding(char, char)
orappendIgnoringWhitespaceAndPadding(char, char)
-
Methods inherited from class com.univocity.parsers.common.input.ExpandingCharAppender
append, append, append, appendUntil, appendUntil, appendUntil, expand, expand, expandAndRetry, fill, prepend, prepend, prepend
-
Methods inherited from class com.univocity.parsers.common.input.DefaultCharAppender
append, append, append, append, append, charAt, delete, getAndReset, getChars, getCharsAndReset, ignore, indexOf, indexOf, indexOf, indexOfAny, isEmpty, lastIndexOf, length, remove, reset, resetWhitespaceCount, subSequence, substring, toString, updateWhitespace, whitespaceCount
-
-
-
-
Constructor Detail
-
WriterCharAppender
public WriterCharAppender(int maxLength, java.lang.String emptyValue, int whitespaceRangeStart, 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
- Parameters:
maxLength
- maximum limit of characters to appendemptyValue
- default value to return when no characters have been accumulatedwhitespaceRangeStart
- starting range of characters considered to be whitespace.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 byFormat.getLineSeparator()
is going to be appended.- Specified by:
appendIgnoringWhitespace
in interfaceCharAppender
- Overrides:
appendIgnoringWhitespace
in classExpandingCharAppender
- 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 characterIf the given character is equal to
Format.getNormalizedNewline()
, then the character sequence returned byFormat.getLineSeparator()
is going to be appended.- Specified by:
appendIgnoringPadding
in interfaceCharAppender
- Overrides:
appendIgnoringPadding
in classExpandingCharAppender
- Parameters:
ch
- character to appendpadding
- 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 characterIf the given character is equal to
Format.getNormalizedNewline()
, then the character sequence returned byFormat.getLineSeparator()
is going to be appended.- Specified by:
appendIgnoringWhitespaceAndPadding
in interfaceCharAppender
- Overrides:
appendIgnoringWhitespaceAndPadding
in classExpandingCharAppender
- Parameters:
ch
- character to appendpadding
- 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 byFormat.getLineSeparator()
is going to be appended.- Specified by:
append
in interfaceCharAppender
- Overrides:
append
in classExpandingCharAppender
- Parameters:
ch
- the character to append
-
writeCharsAndReset
public final void writeCharsAndReset(java.io.Writer writer) throws java.io.IOException
Writes the accumulated value to theWriter
, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char)
,appendIgnoringPadding(char, char)
orappendIgnoringWhitespaceAndPadding(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:
java.io.IOException
- if an error occurs while writing to the output.
-
appendNewLine
public final void appendNewLine()
Appends the newline character sequence specified inFormat.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.
-
-