mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix cv
This commit is contained in:
parent
f729ba7b9c
commit
54a6ba09c6
@ -11,6 +11,7 @@
|
|||||||
* 【db 】 新增条件组,用于处理复杂的where条件(pr#514@Gitee)
|
* 【db 】 新增条件组,用于处理复杂的where条件(pr#514@Gitee)
|
||||||
* 【core 】 新增LocalDateTimeUtil.weekOfYear(issue#I4RWXC@Gitee)
|
* 【core 】 新增LocalDateTimeUtil.weekOfYear(issue#I4RWXC@Gitee)
|
||||||
* 【core 】 Month增加toJdkMonth、getValueBaseOne
|
* 【core 】 Month增加toJdkMonth、getValueBaseOne
|
||||||
|
* 【core 】 CsvWriter修改规则,去除末尾多余换行符(issue#I4RSQY@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复ChineseDate农历获取正月出现数组越界BUG(issue#2112@Github)
|
* 【core 】 修复ChineseDate农历获取正月出现数组越界BUG(issue#2112@Github)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.hutool.core.text.csv;
|
package cn.hutool.core.text.csv;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.ArrayIter;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
@ -45,6 +46,10 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
|||||||
* 是否处于新行开始
|
* 是否处于新行开始
|
||||||
*/
|
*/
|
||||||
private boolean newline = true;
|
private boolean newline = true;
|
||||||
|
/**
|
||||||
|
* 是否首行,即CSV开始的位置,当初始化时默认为true,一旦写入内容,为false
|
||||||
|
*/
|
||||||
|
private boolean isFirstLine = true;
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------- Constructor start
|
// --------------------------------------------------------------------------------------------------- Constructor start
|
||||||
|
|
||||||
@ -183,13 +188,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
|||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public CsvWriter write(String[]... lines) throws IORuntimeException {
|
public CsvWriter write(String[]... lines) throws IORuntimeException {
|
||||||
if (ArrayUtil.isNotEmpty(lines)) {
|
return write(new ArrayIter<>(lines));
|
||||||
for (final String[] values : lines) {
|
|
||||||
appendLine(values);
|
|
||||||
}
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,9 +319,14 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
|||||||
public CsvWriter writeComment(String comment) {
|
public CsvWriter writeComment(String comment) {
|
||||||
Assert.notNull(this.config.commentCharacter, "Comment is disable!");
|
Assert.notNull(this.config.commentCharacter, "Comment is disable!");
|
||||||
try {
|
try {
|
||||||
|
if(isFirstLine){
|
||||||
|
// 首行不补换行符
|
||||||
|
isFirstLine = false;
|
||||||
|
}else {
|
||||||
|
writer.write(config.lineDelimiter);
|
||||||
|
}
|
||||||
writer.write(this.config.commentCharacter);
|
writer.write(this.config.commentCharacter);
|
||||||
writer.write(comment);
|
writer.write(comment);
|
||||||
writer.write(config.lineDelimiter);
|
|
||||||
newline = true;
|
newline = true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IORuntimeException(e);
|
throw new IORuntimeException(e);
|
||||||
@ -366,12 +370,17 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
|||||||
* @param fields 字段列表 ({@code null} 值会被做为空值追加)
|
* @param fields 字段列表 ({@code null} 值会被做为空值追加)
|
||||||
* @throws IOException IO异常
|
* @throws IOException IO异常
|
||||||
*/
|
*/
|
||||||
private void doAppendLine(final String... fields) throws IOException {
|
private void doAppendLine(String... fields) throws IOException {
|
||||||
if (null != fields) {
|
if (null != fields) {
|
||||||
|
if(isFirstLine){
|
||||||
|
// 首行不补换行符
|
||||||
|
isFirstLine = false;
|
||||||
|
}else {
|
||||||
|
writer.write(config.lineDelimiter);
|
||||||
|
}
|
||||||
for (String field : fields) {
|
for (String field : fields) {
|
||||||
appendField(field);
|
appendField(field);
|
||||||
}
|
}
|
||||||
writer.write(config.lineDelimiter);
|
|
||||||
newline = true;
|
newline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package cn.hutool.core.text.csv;
|
|||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CsvWriterTest {
|
public class CsvWriterTest {
|
||||||
@ -19,6 +18,8 @@ public class CsvWriterTest {
|
|||||||
CharsetUtil.CHARSET_GBK, false, csvWriteConfig);
|
CharsetUtil.CHARSET_GBK, false, csvWriteConfig);
|
||||||
|
|
||||||
writer.writeHeaderLine("name", "gender", "address");
|
writer.writeHeaderLine("name", "gender", "address");
|
||||||
|
writer.writeLine("张三", "男", "XX市XX区");
|
||||||
|
writer.writeLine("李四", "男", "XX市XX区,01号");
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,4 +94,6 @@ public class QrCodeUtilTest {
|
|||||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
|
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
|
||||||
Assert.assertNotNull(image);
|
Assert.assertNotNull(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user