增加CsvWriteConfig.setEndingLineBreak配置项

This commit is contained in:
Looly 2023-05-20 03:17:29 +08:00
parent d8b9b5cad1
commit a61175f425
3 changed files with 24 additions and 0 deletions

View File

@ -13,6 +13,7 @@
* 【core 】 FileUtil.getMimeType增加webp识别pr#997@Gitee
* 【core 】 SyncFinisher增加setExceptionHandler方法issue#I716SX@Gitee
* 【core 】 FileTypeUtil.getType增加文件判断pr#3112@Github
* 【core 】 增加CsvWriteConfig.setEndingLineBreak配置项issue#I75K5G@Gitee
### 🐞Bug修复
* 【core 】 修复URLUtil.decode无法解码UTF-16问题issue#3063@Github

View File

@ -21,6 +21,12 @@ public class CsvWriteConfig extends CsvConfig<CsvWriteConfig> implements Seriali
*/
protected char[] lineDelimiter = {CharUtil.CR, CharUtil.LF};
/**
* 文件末尾是否添加换行符<br>
* 按照https://datatracker.ietf.org/doc/html/rfc4180#section-2 规范末尾换行符可有可无
*/
protected boolean endingLineBreak;
/**
* 默认配置
*
@ -51,4 +57,16 @@ public class CsvWriteConfig extends CsvConfig<CsvWriteConfig> implements Seriali
this.lineDelimiter = lineDelimiter;
return this;
}
/**
* 文件末尾是否添加换行符<br>
* 按照https://datatracker.ietf.org/doc/html/rfc4180#section-2 规范末尾换行符可有可无
*
* @param endingLineBreak 文件末尾是否添加换行符
* @return this
*/
public CsvWriteConfig setEndingLineBreak(boolean endingLineBreak) {
this.endingLineBreak = endingLineBreak;
return this;
}
}

View File

@ -334,8 +334,13 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
return this;
}
@SuppressWarnings("resource")
@Override
public void close() {
if(this.config.endingLineBreak){
//https://gitee.com/dromara/hutool/issues/I75K5G
writeLine();
}
IoUtil.close(this.writer);
}