CharsetDetector增加默认识别的长度

This commit is contained in:
Looly
2022-09-26 22:52:13 +08:00
parent bef38c365b
commit 52496bb62f
3 changed files with 12 additions and 2 deletions

View File

@@ -60,7 +60,7 @@ public class CharsetDetector {
* @return 编码
*/
public static Charset detect(InputStream in, Charset... charsets) {
return detect(IoUtil.DEFAULT_BUFFER_SIZE, in, charsets);
return detect(IoUtil.DEFAULT_LARGE_BUFFER_SIZE, in, charsets);
}
/**

View File

@@ -3,6 +3,7 @@ package cn.hutool.core.io;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.nio.charset.Charset;
@@ -16,4 +17,12 @@ public class CharsetDetectorTest {
CharsetUtil.CHARSET_GBK, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals(CharsetUtil.CHARSET_UTF_8, detect);
}
@Test
@Ignore
public void issue2547() {
final Charset detect = CharsetDetector.detect(IoUtil.DEFAULT_LARGE_BUFFER_SIZE,
ResourceUtil.getStream("d:/test/default.txt"));
Assert.assertEquals(CharsetUtil.CHARSET_UTF_8, detect);
}
}