mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -12,12 +12,7 @@ import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* CSV行解析器,参考:FastCSV
|
||||
@@ -32,7 +27,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
private final Reader reader;
|
||||
private final CsvReadConfig config;
|
||||
|
||||
private final Buffer buf = new Buffer(IoUtil.DEFAULT_LARGE_BUFFER_SIZE);
|
||||
private final Buffer buf;
|
||||
/**
|
||||
* 前一个特殊分界字符
|
||||
*/
|
||||
@@ -78,8 +73,20 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
* @param config 配置,null则为默认配置
|
||||
*/
|
||||
public CsvParser(final Reader reader, final CsvReadConfig config) {
|
||||
this(reader, config, IoUtil.DEFAULT_LARGE_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* CSV解析器
|
||||
*
|
||||
* @param reader Reader
|
||||
* @param config 配置,null则为默认配置
|
||||
* @param bufferSize 默认缓存大小
|
||||
*/
|
||||
public CsvParser(final Reader reader, final CsvReadConfig config, final int bufferSize) {
|
||||
this.reader = Objects.requireNonNull(reader, "reader must not be null");
|
||||
this.config = ObjUtil.defaultIfNull(config, CsvReadConfig::defaultConfig);
|
||||
this.buf = new Buffer(bufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,13 +1,12 @@
|
||||
package cn.hutool.poi.csv;
|
||||
|
||||
import cn.hutool.core.io.file.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileUtil;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Path;
|
||||
@@ -132,14 +131,9 @@ public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closea
|
||||
* @since 5.7.14
|
||||
*/
|
||||
public Stream<CsvRow> stream() {
|
||||
return StreamSupport.stream(spliterator(), false)
|
||||
.onClose(() -> {
|
||||
try {
|
||||
close();
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
});
|
||||
return StreamSupport
|
||||
.stream(spliterator(), false)
|
||||
.onClose(this::close);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,7 +142,7 @@ public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closea
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
IoUtil.close(this.reader);
|
||||
}
|
||||
}
|
||||
|
@@ -73,21 +73,11 @@ public class NullCell implements Cell {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CellType getCellTypeEnum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellType getCachedFormulaResultType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CellType getCachedFormulaResultTypeEnum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCellValue(final double value) {
|
||||
throw new UnsupportedOperationException("Can not set any thing to null cell!");
|
||||
|
@@ -11,12 +11,14 @@ public class Issue2783Test {
|
||||
@Test
|
||||
@Ignore
|
||||
public void readTest() {
|
||||
// final CsvWriter writer = CsvUtil.getWriter("d:/test/big.csv", CharsetUtil.UTF_8);
|
||||
// for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||
// writer.writeLine("aaaa", "bbbb", "ccccc", "dddd");
|
||||
// }
|
||||
// writer.close();
|
||||
// 测试数据
|
||||
final CsvWriter writer = CsvUtil.getWriter("d:/test/big.csv", CharsetUtil.UTF_8);
|
||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||
writer.writeLine("aaaa", "bbbb", "ccccc", "dddd");
|
||||
}
|
||||
writer.close();
|
||||
|
||||
// 读取
|
||||
final CsvReader reader = CsvUtil.getReader(FileUtil.getReader("d:/test/big.csv", CharsetUtil.UTF_8));
|
||||
reader.read((SerConsumer<CsvRow>) strings -> {
|
||||
|
||||
|
Reference in New Issue
Block a user