public class WriterCharAppender extends ExpandingCharAppender
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.
Format
,
AbstractWriter
Constructor and Description |
---|
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
The padding character is defaulted to a whitespace character ' '. |
Modifier and Type | Method and 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 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) |
append, append, append, appendUntil, appendUntil, appendUntil, fill, prepend, prepend, prepend
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
chars, codePoints
public WriterCharAppender(int maxLength, String emptyValue, int whitespaceRangeStart, Format format)
Format
specification for handling newlinesmaxLength
- 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 handlingpublic final void appendIgnoringWhitespace(char ch)
ch <= ' '
)
If the given character is equal to Format.getNormalizedNewline()
, then the character sequence returned by Format.getLineSeparator()
is going to be appended.
appendIgnoringWhitespace
in interface CharAppender
appendIgnoringWhitespace
in class ExpandingCharAppender
ch
- character to appendpublic final void appendIgnoringPadding(char ch, char padding)
If the given character is equal to Format.getNormalizedNewline()
, then the character sequence returned by Format.getLineSeparator()
is going to be appended.
appendIgnoringPadding
in interface CharAppender
appendIgnoringPadding
in class ExpandingCharAppender
ch
- character to appendpadding
- the padding characterpublic final void appendIgnoringWhitespaceAndPadding(char ch, char padding)
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.
appendIgnoringWhitespaceAndPadding
in interface CharAppender
appendIgnoringWhitespaceAndPadding
in class ExpandingCharAppender
ch
- character to appendpadding
- the padding characterpublic final void append(char ch)
If the given character is equal to Format.getNormalizedNewline()
, then the character sequence returned by Format.getLineSeparator()
is going to be appended.
append
in interface CharAppender
append
in class ExpandingCharAppender
ch
- the character to appendpublic final void writeCharsAndReset(Writer writer) throws IOException
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.
writer
- the output writerIOException
- if an error occurs while writing to the output.public final void appendNewLine()
Format.getLineSeparator()
public final void enableDenormalizedLineEndings(boolean enableDenormalizedLineEndings)
enableDenormalizedLineEndings
- flag indicating whether denormalized line endings are allowed. The writer
won't convert line separators automatically.Copyright © 2019 Univocity Software Pty Ltd. All rights reserved.