Class WriterCharAppender
- All Implemented Interfaces:
CharAppender
,CharSequence
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final char
private final char
private final char
Fields inherited from class com.univocity.parsers.common.input.DefaultCharAppender
chars, emptyChars, emptyValue, index, whitespaceCount, whitespaceRangeStart
-
Constructor Summary
ConstructorsConstructorDescriptionWriterCharAppender
(int maxLength, 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
Modifier and TypeMethodDescriptionfinal void
append
(char ch) Appends the given character.final void
appendIgnoringPadding
(char ch, char padding) Appends the given character and marks it as ignored if it is a padding characterfinal void
appendIgnoringWhitespace
(char ch) Appends the given character and marks it as ignored if it is a whitespace (ch <= ' '
)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 characterfinal void
Appends the newline character sequence specified inFormat.getLineSeparator()
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.final void
writeCharsAndReset
(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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
lineSeparator1
private final char lineSeparator1 -
lineSeparator2
private final char lineSeparator2 -
newLine
private final char newLine -
denormalizeLineEndings
private boolean denormalizeLineEndings
-
-
Constructor Details
-
WriterCharAppender
public WriterCharAppender(int maxLength, 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 Details
-
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
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:
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.
-