mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bom
This commit is contained in:
parent
b7ca34d0e8
commit
93df8333df
@ -108,4 +108,11 @@ public class CaptchaTest {
|
|||||||
captcha.write("d:/test/gif_captcha.gif");
|
captcha.write("d:/test/gif_captcha.gif");
|
||||||
assert captcha.verify(captcha.getCode());
|
assert captcha.verify(captcha.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bgTest(){
|
||||||
|
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 100, 4, 1);
|
||||||
|
captcha.setBackground(Color.WHITE);
|
||||||
|
captcha.write("d:/test/test.jpg");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package cn.hutool.core.io;
|
package cn.hutool.core.io;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PushbackInputStream;
|
import java.io.PushbackInputStream;
|
||||||
|
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取带BOM头的流内容,<code>getCharset()</code>方法调用后会得到BOM头的编码,且会去除BOM头<br>
|
* 读取带BOM头的流内容,{@code getCharset()}方法调用后会得到BOM头的编码,且会去除BOM头<br>
|
||||||
* BOM定义:http://www.unicode.org/unicode/faq/utf_bom.html<br>
|
* BOM定义:http://www.unicode.org/unicode/faq/utf_bom.html<br>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>00 00 FE FF = UTF-32, big-endian</li>
|
* <li>00 00 FE FF = UTF-32, big-endian</li>
|
||||||
@ -46,10 +46,20 @@ public class BOMInputStream extends InputStream {
|
|||||||
}
|
}
|
||||||
// ----------------------------------------------------------------- Constructor end
|
// ----------------------------------------------------------------- Constructor end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取默认编码
|
||||||
|
*
|
||||||
|
* @return 默认编码
|
||||||
|
*/
|
||||||
public String getDefaultCharset() {
|
public String getDefaultCharset() {
|
||||||
return defaultCharset;
|
return defaultCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取BOM头中的编码
|
||||||
|
*
|
||||||
|
* @return 编码
|
||||||
|
*/
|
||||||
public String getCharset() {
|
public String getCharset() {
|
||||||
if (!isInited) {
|
if (!isInited) {
|
||||||
try {
|
try {
|
||||||
|
@ -1019,8 +1019,8 @@ public class FileUtil extends PathUtil {
|
|||||||
* @param isRetainExt 是否保留原文件的扩展名,如果保留,则newName不需要加扩展名
|
* @param isRetainExt 是否保留原文件的扩展名,如果保留,则newName不需要加扩展名
|
||||||
* @param isOverride 是否覆盖目标文件
|
* @param isOverride 是否覆盖目标文件
|
||||||
* @return 目标文件
|
* @return 目标文件
|
||||||
* @since 3.0.9
|
|
||||||
* @see PathUtil#rename(Path, String, boolean)
|
* @see PathUtil#rename(Path, String, boolean)
|
||||||
|
* @since 3.0.9
|
||||||
*/
|
*/
|
||||||
public static File rename(File file, String newName, boolean isRetainExt, boolean isOverride) {
|
public static File rename(File file, String newName, boolean isRetainExt, boolean isOverride) {
|
||||||
if (isRetainExt) {
|
if (isRetainExt) {
|
||||||
@ -1704,6 +1704,17 @@ public class FileUtil extends PathUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取带BOM头的文件为Reader
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return BufferedReader对象
|
||||||
|
* @since 5.5.8
|
||||||
|
*/
|
||||||
|
public static BufferedReader getBOMReader(File file) {
|
||||||
|
return IoUtil.getReader(getBOMInputStream(file));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得一个文件读取器
|
* 获得一个文件读取器
|
||||||
*
|
*
|
||||||
|
@ -222,6 +222,17 @@ public class IoUtil extends NioUtil {
|
|||||||
return getReader(in, Charset.forName(charsetName));
|
return getReader(in, Charset.forName(charsetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从{@link BOMInputStream}中获取Reader
|
||||||
|
*
|
||||||
|
* @param in {@link BOMInputStream}
|
||||||
|
* @return {@link BufferedReader}
|
||||||
|
* @since 5.5.8
|
||||||
|
*/
|
||||||
|
public static BufferedReader getReader(BOMInputStream in) {
|
||||||
|
return getReader(in, in.getCharset());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得一个Reader
|
* 获得一个Reader
|
||||||
*
|
*
|
||||||
|
@ -118,7 +118,7 @@ public class FileUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equlasTest() {
|
public void equalsTest() {
|
||||||
// 源文件和目标文件都不存在
|
// 源文件和目标文件都不存在
|
||||||
File srcFile = FileUtil.file("d:/hutool.jpg");
|
File srcFile = FileUtil.file("d:/hutool.jpg");
|
||||||
File destFile = FileUtil.file("d:/hutool.jpg");
|
File destFile = FileUtil.file("d:/hutool.jpg");
|
||||||
|
@ -42,4 +42,12 @@ public class ExcelUtilTest {
|
|||||||
Assert.assertEquals(0, a11.getX());
|
Assert.assertEquals(0, a11.getX());
|
||||||
Assert.assertEquals(10, a11.getY());
|
Assert.assertEquals(10, a11.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readAndWriteTest(){
|
||||||
|
ExcelReader reader = ExcelUtil.getReader("d:\\test/select.xls");
|
||||||
|
ExcelWriter writer = reader.getWriter();
|
||||||
|
writer.writeCellValue(1, 2, "设置值");
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user