Skip to content

Commit

Permalink
fix csv export error (#4814)
Browse files Browse the repository at this point in the history
  • Loading branch information
aiceflower authored Jul 25, 2023
1 parent 1cbd17f commit 0f07511
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ public StorageCSVWriter(
this.quoteRetouchEnable = quoteRetouchEnable;
this.outputStream = outputStream;

this.delimiter = StringUtils.isNotEmpty(separator) ? separator : "\t";
if (StringUtils.isBlank(separator)) {
this.delimiter = "\t";
} else {
switch (separator) {
case "t":
this.delimiter = "\t";
break;
default:
this.delimiter = separator;
break;
}
}
this.buffer = new StringBuilder(50000);
}

Expand Down Expand Up @@ -90,6 +101,10 @@ private String compact(String[] row) {
: value;
rowBuilder.append(decoratedValue).append(delimiter);
}
if (rowBuilder.length() > 0 && rowBuilder.toString().endsWith(delimiter)) {
int index = rowBuilder.lastIndexOf(separator);
rowBuilder.delete(index, index + separator.length());
}
rowBuilder.append("\n");
if (logger.isDebugEnabled()) {
logger.debug("delimiter:" + delimiter);
Expand Down

0 comments on commit 0f07511

Please sign in to comment.