Top Description Fields Constructors Methods
com.univocity.parsers.common.input

public Class WriterCharAppender

extends ExpandingCharAppender
Class Inheritance
Imports
com.univocity.parsers.common.*, java.io.*

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 java.io.Writer directly to avoid unnecessary String instantiations.

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.common.Format, com.univocity.parsers.common.AbstractWriter

Field Summary

Modifier and TypeField and Description
private boolean
private final char
private final char
private final char

Constructor Summary

AccessConstructor and Description
public
WriterCharAppender(int
maximum limit of characters to append
maxLength
,
String
default value to return when no characters have been accumulated
emptyValue
,
int
starting range of characters considered to be whitespace.
whitespaceRangeStart
,
Format
output format specification used for newline handling
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

Method Summary

Modifier and TypeMethod and Description
public final void
append(char
the character to append
ch
)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.append.

Implements com.univocity.parsers.common.input.CharAppender.append.

Appends the given character.
public final void
appendIgnoringPadding(char
character to append
ch
,
char
the padding character
padding
)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.appendIgnoringPadding.

Implements com.univocity.parsers.common.input.CharAppender.appendIgnoringPadding.

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.

public final void
appendIgnoringWhitespace(char
character to append
ch
)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.appendIgnoringWhitespace.

Implements com.univocity.parsers.common.input.CharAppender.appendIgnoringWhitespace.

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.

public final void
appendIgnoringWhitespaceAndPadding(char
character to append
ch
,
char
the padding character
padding
)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.appendIgnoringWhitespaceAndPadding.

Implements com.univocity.parsers.common.input.CharAppender.appendIgnoringWhitespaceAndPadding.

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.

public final void
appendNewLine()

Appends the newline character sequence specified in Format#getLineSeparator()

public final void
enableDenormalizedLineEndings(boolean
flag indicating whether denormalized line endings are allowed. The writer won't convert line separators automatically.
enableDenormalizedLineEndings
)

Configures the appender to allow line ending sequences to be appended as-is, without replacing them by the normalized line separator character.

public final void
writeCharsAndReset(Writer
the output writer
writer
)

Writes the accumulated value to the java.io.Writer, discarding any trailing whitespace characters identified when using WriterCharAppender#appendIgnoringWhitespace(char), WriterCharAppender#appendIgnoringPadding(char, char) or WriterCharAppender#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.

Inherited from com.univocity.parsers.common.input.ExpandingCharAppender:
appendappendappendappendUntilappendUntilappendUntilexpandexpandexpandAndRetryfillprependprependprepend

Field Detail

denormalizeLineEndingsback to summary
private boolean denormalizeLineEndings
lineSeparator1back to summary
private final char lineSeparator1
lineSeparator2back to summary
private final char lineSeparator2
newLineback to summary
private final char newLine

Constructor Detail

WriterCharAppenderback to summary
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
The padding character is defaulted to a whitespace character ' '.
Parameters
maxLength:int

maximum limit of characters to append

emptyValue:String

default value to return when no characters have been accumulated

whitespaceRangeStart:int

starting range of characters considered to be whitespace.

format:Format

output format specification used for newline handling

Method Detail

appendback to summary
public final void append(char ch)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.append.

Implements com.univocity.parsers.common.input.CharAppender.append.

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.

Parameters
ch:char

the character to append

Annotations
@Override
appendIgnoringPaddingback to summary
public final void appendIgnoringPadding(char ch, char padding)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.appendIgnoringPadding.

Implements com.univocity.parsers.common.input.CharAppender.appendIgnoringPadding.

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.

Parameters
ch:char

character to append

padding:char

the padding character

Annotations
@Override
appendIgnoringWhitespaceback to summary
public final void appendIgnoringWhitespace(char ch)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.appendIgnoringWhitespace.

Implements com.univocity.parsers.common.input.CharAppender.appendIgnoringWhitespace.

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.

Parameters
ch:char

character to append

Annotations
@Override
appendIgnoringWhitespaceAndPaddingback to summary
public final void appendIgnoringWhitespaceAndPadding(char ch, char padding)

Overrides com.univocity.parsers.common.input.ExpandingCharAppender.appendIgnoringWhitespaceAndPadding.

Implements com.univocity.parsers.common.input.CharAppender.appendIgnoringWhitespaceAndPadding.

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.

Parameters
ch:char

character to append

padding:char

the padding character

Annotations
@Override
appendNewLineback to summary
public final void appendNewLine()

Appends the newline character sequence specified in Format#getLineSeparator()

enableDenormalizedLineEndingsback to summary
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:boolean

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

writeCharsAndResetback to summary
public final void writeCharsAndReset(Writer writer) throws IOException

Writes the accumulated value to the java.io.Writer, discarding any trailing whitespace characters identified when using WriterCharAppender#appendIgnoringWhitespace(char), WriterCharAppender#appendIgnoringPadding(char, char) or WriterCharAppender#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:Writer

the output writer

Exceptions
IOException:
if an error occurs while writing to the output.