mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
3eef8aa6ec
commit
b7d91489f4
@ -6,8 +6,8 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.mutable.MutableEntry;
|
||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||
import cn.hutool.core.map.MapWrapper;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.reflect.TypeUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
@ -3,10 +3,8 @@ package cn.hutool.core.io;
|
||||
import cn.hutool.core.io.stream.BOMInputStream;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
@ -29,9 +27,7 @@ import java.io.UnsupportedEncodingException;
|
||||
* @author looly
|
||||
* @since 5.7.14
|
||||
*/
|
||||
public class BomReader extends Reader {
|
||||
|
||||
private InputStreamReader reader;
|
||||
public class BomReader extends ReaderWrapper {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
@ -39,22 +35,22 @@ public class BomReader extends Reader {
|
||||
* @param in 流
|
||||
*/
|
||||
public BomReader(final InputStream in) {
|
||||
super(initReader(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化为{@link InputStreamReader},将给定流转换为{@link BOMInputStream}
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @return {@link InputStreamReader}
|
||||
*/
|
||||
private static InputStreamReader initReader(final InputStream in) {
|
||||
Assert.notNull(in, "InputStream must be not null!");
|
||||
final BOMInputStream bin = (in instanceof BOMInputStream) ? (BOMInputStream) in : new BOMInputStream(in);
|
||||
try {
|
||||
this.reader = new InputStreamReader(bin, bin.getCharset());
|
||||
} catch (final UnsupportedEncodingException ignore) {
|
||||
return new InputStreamReader(bin, bin.getCharset());
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public int read(final char[] buffer, final int off, final int len) throws IOException {
|
||||
return reader.read(buffer, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
54
hutool-core/src/main/java/cn/hutool/core/io/LineReader.java
Executable file
54
hutool-core/src/main/java/cn/hutool/core/io/LineReader.java
Executable file
@ -0,0 +1,54 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* 行读取器,类似于BufferedInputStream,支持注释和多行转义
|
||||
* TODO 待实现
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class LineReader extends ReaderWrapper {
|
||||
|
||||
/**
|
||||
* 注释标识符
|
||||
*/
|
||||
private char[] commentFlags;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param reader {@link Reader}
|
||||
*/
|
||||
public LineReader(final Reader reader) {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置注释行标识符
|
||||
*
|
||||
* @param commentFlags 注释行标识符
|
||||
* @return this
|
||||
*/
|
||||
public LineReader setCommentFlags(final char... commentFlags) {
|
||||
if (ArrayUtil.isEmpty(commentFlags)) {
|
||||
// 无注释行
|
||||
this.commentFlags = null;
|
||||
}
|
||||
this.commentFlags = ArrayUtil.copy(commentFlags, new char[commentFlags.length]);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取一行
|
||||
*
|
||||
* @return 内容
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public String readLine() throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
60
hutool-core/src/main/java/cn/hutool/core/io/ReaderWrapper.java
Executable file
60
hutool-core/src/main/java/cn/hutool/core/io/ReaderWrapper.java
Executable file
@ -0,0 +1,60 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.Wrapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
/**
|
||||
* {@link Reader} 包装
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class ReaderWrapper extends Reader implements Wrapper<Reader> {
|
||||
|
||||
protected final Reader raw;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param reader {@link Reader}
|
||||
*/
|
||||
public ReaderWrapper(final Reader reader) {
|
||||
this.raw = Assert.notNull(reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getRaw() {
|
||||
return this.raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return raw.read();
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public int read(final CharBuffer target) throws IOException {
|
||||
return raw.read(target);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public int read(final char[] cbuf) throws IOException {
|
||||
return raw.read(cbuf);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public int read(final char[] buffer, final int off, final int len) throws IOException {
|
||||
return raw.read(buffer, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
raw.close();
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ public interface CharPool {
|
||||
/**
|
||||
* 字符常量:制表符 {@code '\t'}
|
||||
*/
|
||||
char TAB = ' ';
|
||||
char TAB = '\t';
|
||||
/**
|
||||
* 字符常量:点 {@code '.'}
|
||||
*/
|
||||
|
@ -515,8 +515,8 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
||||
* @param array 原数组
|
||||
* @param newSize 新的数组大小
|
||||
* @return 调整后的新数组
|
||||
* @since 4.6.7
|
||||
* @see System#arraycopy(Object, int, Object, int, int)
|
||||
* @since 4.6.7
|
||||
*/
|
||||
public static Object resize(final Object array, final int newSize) {
|
||||
if (newSize < 0) {
|
||||
@ -579,10 +579,39 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装 {@link System#arraycopy(Object, int, Object, int, int)}<br>
|
||||
* 数组复制,缘数组和目标数组都是从位置0开始复制,复制长度为源数组的长度
|
||||
*
|
||||
* @param <T> 目标数组类型
|
||||
* @param src 源数组
|
||||
* @param dest 目标数组
|
||||
* @return 目标数组
|
||||
*/
|
||||
public static <T> T copy(final Object src, final T dest) {
|
||||
return copy(src, dest, length(src));
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装 {@link System#arraycopy(Object, int, Object, int, int)}<br>
|
||||
* 数组复制,缘数组和目标数组都是从位置0开始复制
|
||||
*
|
||||
* @param <T> 目标数组类型
|
||||
* @param src 源数组
|
||||
* @param dest 目标数组
|
||||
* @param length 拷贝数组长度
|
||||
* @return 目标数组
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public static <T> T copy(final Object src, final T dest, final int length) {
|
||||
return copy(src, 0, dest, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装 {@link System#arraycopy(Object, int, Object, int, int)}<br>
|
||||
* 数组复制
|
||||
*
|
||||
* @param <T> 目标数组类型
|
||||
* @param src 源数组
|
||||
* @param srcPos 源数组开始位置
|
||||
* @param dest 目标数组
|
||||
@ -591,28 +620,12 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
||||
* @return 目标数组
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public static Object copy(final Object src, final int srcPos, final Object dest, final int destPos, final int length) {
|
||||
public static <T> T copy(final Object src, final int srcPos, final T dest, final int destPos, final int length) {
|
||||
//noinspection SuspiciousSystemArraycopy
|
||||
System.arraycopy(src, srcPos, dest, destPos, length);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装 {@link System#arraycopy(Object, int, Object, int, int)}<br>
|
||||
* 数组复制,缘数组和目标数组都是从位置0开始复制
|
||||
*
|
||||
* @param src 源数组
|
||||
* @param dest 目标数组
|
||||
* @param length 拷贝数组长度
|
||||
* @return 目标数组
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public static Object copy(final Object src, final Object dest, final int length) {
|
||||
//noinspection SuspiciousSystemArraycopy
|
||||
System.arraycopy(src, 0, dest, 0, length);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 克隆数组
|
||||
*
|
||||
|
11
hutool-core/src/test/java/cn/hutool/core/io/LineReaderTest.java
Executable file
11
hutool-core/src/test/java/cn/hutool/core/io/LineReaderTest.java
Executable file
@ -0,0 +1,11 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LineReaderTest {
|
||||
@Test
|
||||
public void readTest() throws IOException {
|
||||
}
|
||||
}
|
27
hutool-core/src/test/resources/multi_line.properties
Executable file
27
hutool-core/src/test/resources/multi_line.properties
Executable file
@ -0,0 +1,27 @@
|
||||
client.mode=single
|
||||
configure={\
|
||||
"singleServerConfig":{\
|
||||
"idleConnectionTimeout":10000,\
|
||||
"pingTimeout":1000, \
|
||||
"connectTimeout":10000, \
|
||||
"timeout":3000,\
|
||||
"retryAttempts":3,\
|
||||
"retryInterval":1500,\
|
||||
"reconnectionTimeout":3000,\
|
||||
"failedAttempts":3,\
|
||||
"password":null,\
|
||||
"subscriptionsPerConnection":5,\
|
||||
"clientName":null,\
|
||||
"address": "redis://127.0.0.1:6379",\
|
||||
"subscriptionConnectionMinimumIdleSize":1,\
|
||||
"subscriptionConnectionPoolSize":50,\
|
||||
"connectionMinimumIdleSize":12,\
|
||||
"connectionPoolSize":12\
|
||||
},\
|
||||
"threads":2,\
|
||||
"nettyThreads":2,\
|
||||
"codec":{\
|
||||
"class":"org.redisson.client.codec.StringCodec"\
|
||||
},\
|
||||
"transportMode":"NIO"\
|
||||
}
|
@ -821,7 +821,7 @@ public class ExcelWriteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Ignore
|
||||
@Ignore
|
||||
public void writeDoubleTest() {
|
||||
// https://gitee.com/dromara/hutool/issues/I5PI5C
|
||||
final String path = "d:/test/doubleTest.xlsx";
|
||||
|
Loading…
x
Reference in New Issue
Block a user