[
https://issues.apache.org/jira/browse/SANDBOX-243?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henri Yandell updated SANDBOX-243:
----------------------------------
Fix Version/s: (was: Nightly Builds)
CSV 1.0
Fix for 1.0 - assuming we keep this package in 1.0.
> CSVWriter.writeValue() not using value delimiter
> ------------------------------------------------
>
> Key: SANDBOX-243
> URL: https://issues.apache.org/jira/browse/SANDBOX-243
> Project: Commons Sandbox
> Issue Type: Bug
> Components: CSV
> Affects Versions: Nightly Builds
> Reporter: Mike Cordes
> Priority: Minor
> Fix For: CSV 1.0
>
> Original Estimate: 0.08h
> Remaining Estimate: 0.08h
>
> CSVWriter.writeValue() only uses value delimiter if field values are fixed
> width.
> Here is the existing method:
> {code:title=CSVWriter.writeValue() error|borderStyle=solid}
> protected String writeValue(CSVField field, String value) throws Exception {
> if (config.isFixedWidth()) {
> if (value.length() < field.getSize()) {
> int fillPattern = config.getFill();
> if (field.overrideFill()) {
> fillPattern = field.getFill();
> }
> StringBuffer sb = new StringBuffer();
> int fillSize = (field.getSize() - value.length());
> char[] fill = new char[fillSize];
> Arrays.fill(fill, config.getFillChar());
> if (fillPattern == CSVConfig.FILLLEFT) {
> sb.append(fill);
> sb.append(value);
> value = sb.toString();
> } else {
> // defaults to fillpattern FILLRIGHT when fixedwidth is
> used
> sb.append(value);
> sb.append(fill);
> value = sb.toString();
> }
> } else if (value.length() > field.getSize()) {
> // value to big..
> value = value.substring(0, field.getSize());
> }
> if (!config.isValueDelimiterIgnored()) {
> // add the value delimiter..
> value =
> config.getValueDelimiter()+value+config.getValueDelimiter();
> }
> }
> return value;
> }
> {code}
> The {color:blue}{{if (!config.isValueDelimiterIgnored())}}{color} block
> should be removed from the {color:blue}{{if (config.isFixedWidth())}}{color}
> block, like so:
> {code:title=CSVWriter.writeValue() corrected|borderStyle=solid}
> protected String writeValue(CSVField field, String value) throws Exception {
> if (config.isFixedWidth()) {
> if (value.length() < field.getSize()) {
> int fillPattern = config.getFill();
> if (field.overrideFill()) {
> fillPattern = field.getFill();
> }
> StringBuffer sb = new StringBuffer();
> int fillSize = (field.getSize() - value.length());
> char[] fill = new char[fillSize];
> Arrays.fill(fill, config.getFillChar());
> if (fillPattern == CSVConfig.FILLLEFT) {
> sb.append(fill);
> sb.append(value);
> value = sb.toString();
> } else {
> // defaults to fillpattern FILLRIGHT when fixedwidth is
> used
> sb.append(value);
> sb.append(fill);
> value = sb.toString();
> }
> } else if (value.length() > field.getSize()) {
> // value to big..
> value = value.substring(0, field.getSize());
> }
> }
> if (!config.isValueDelimiterIgnored()) {
> // add the value delimiter..
> value =
> config.getValueDelimiter()+value+config.getValueDelimiter();
> }
> return value;
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.