in src/main/java/com/univocity/parsers/fixed/FixedWidthWriter.java [293:333]
private void append(String element) {
int start = 0;
if (this.ignoreLeading) {
start = skipLeadingWhitespace(whitespaceRangeStart, element);
}
int padCount = alignment.calculatePadding(length, element.length() - start);
length -= padCount;
appender.fill(padding, padCount);
if (this.ignoreTrailing) {
int i = start;
while (i < element.length() && length > 0) {
for (; i < element.length() && length-- > 0; i++) {
char nextChar = element.charAt(i);
appender.appendIgnoringWhitespace(nextChar);
}
if (length == -1 && appender.whitespaceCount() > 0) {
//if we got here then the value to write got truncated exactly after one or more whitespaces.
//In this case, if the whitespaces are not at the end of the truncated value they will be put back to the output.
for (int j = i; j < element.length(); j++) {
if (element.charAt(j) > ' ') {
//resets the whitespace count so the original whitespaces are printed to the output.
appender.resetWhitespaceCount();
break;
}
}
if (appender.whitespaceCount() > 0) {
length = 0;
}
}
length += appender.whitespaceCount();
appendValueToRow();
}
} else {
for (int i = start; i < element.length() && length-- > 0; i++) {
char nextChar = element.charAt(i);
appender.append(nextChar);
}
}
}