fix FileResourceBug

This commit is contained in:
Looly 2021-11-10 22:48:11 +08:00
parent d53f1ff15e
commit 662485fb2b
8 changed files with 35 additions and 28 deletions

View File

@ -3,10 +3,11 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.17 (2021-11-07)
# 5.7.17 (2021-11-10)
### 🐣新特性
### 🐞Bug修复
* 【core 】 修复FileResource构造fileName参数无效问题issue#1942@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -1,6 +1,8 @@
package cn.hutool.core.io.resource;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.URLUtil;
import java.io.File;
@ -18,11 +20,21 @@ public class FileResource implements Resource, Serializable {
private static final long serialVersionUID = 1L;
private final File file;
private final String name;
// ----------------------------------------------------------------------- Constructor start
/**
* 构造
*
* @param path 文件绝对路径或相对ClassPath路径但是这个路径不能指向一个jar包中的文件
*/
public FileResource(String path) {
this(FileUtil.file(path));
}
/**
* 构造文件名使用文件本身的名字带扩展名
*
* @param path 文件
* @since 4.4.1
*/
@ -31,37 +43,31 @@ public class FileResource implements Resource, Serializable {
}
/**
* 构造
* 构造文件名使用文件本身的名字带扩展名
*
* @param file 文件
*/
public FileResource(File file) {
this(file, file.getName());
this(file, null);
}
/**
* 构造
*
* @param file 文件
* @param fileName 文件名如果为null获取文件本身的文件名
* @param fileName 文件名带扩展名如果为null获取文件本身的文件名
*/
public FileResource(File file, String fileName) {
Assert.notNull(file, "File must be not null !");
this.file = file;
this.name = ObjectUtil.defaultIfNull(fileName, file.getName());
}
/**
* 构造
*
* @param path 文件绝对路径或相对ClassPath路径但是这个路径不能指向一个jar包中的文件
*/
public FileResource(String path) {
this(FileUtil.file(path));
}
// ----------------------------------------------------------------------- Constructor end
@Override
public String getName() {
return this.file.getName();
return this.name;
}
@Override
@ -89,6 +95,6 @@ public class FileResource implements Resource, Serializable {
*/
@Override
public String toString() {
return (null == this.file) ? "null" : this.file.toString();
return this.file.toString();
}
}

View File

@ -4,14 +4,14 @@ import org.junit.Assert;
import org.junit.Test;
public class ZodiacTest {
@Test
public void getZodiacTest() {
Assert.assertEquals("摩羯座", Zodiac.getZodiac(Month.JANUARY, 19));
Assert.assertEquals("水瓶座", Zodiac.getZodiac(Month.JANUARY, 20));
Assert.assertEquals("巨蟹座", Zodiac.getZodiac(6, 17));
}
@Test
public void getChineseZodiacTest() {
Assert.assertEquals("", Zodiac.getChineseZodiac(1994));

View File

@ -40,12 +40,12 @@ public abstract class AbstractRowHandler<T> implements RowHandler {
}
@Override
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
Assert.notNull(convertFunc);
if (rowIndex < this.startRowIndex || rowIndex > this.endRowIndex) {
return;
}
handleData(sheetIndex, rowIndex, convertFunc.callWithRuntimeException(rowList));
handleData(sheetIndex, rowIndex, convertFunc.callWithRuntimeException(rowCells));
}
/**

View File

@ -42,11 +42,11 @@ public abstract class BeanRowHandler<T> extends AbstractRowHandler<T> {
}
@Override
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
if (rowIndex == this.headerRowIndex) {
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowList));
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowCells));
return;
}
super.handle(sheetIndex, rowIndex, rowList);
super.handle(sheetIndex, rowIndex, rowCells);
}
}

View File

@ -39,11 +39,11 @@ public abstract class MapRowHandler extends AbstractRowHandler<Map<String, Objec
}
@Override
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
if (rowIndex == this.headerRowIndex) {
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowList));
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowCells));
return;
}
super.handle(sheetIndex, rowIndex, rowList);
super.handle(sheetIndex, rowIndex, rowCells);
}
}

View File

@ -17,9 +17,9 @@ public interface RowHandler {
*
* @param sheetIndex 当前Sheet序号
* @param rowIndex 当前行号从0开始计数
* @param rowList 行数据列表
* @param rowCells 行数据每个Object表示一个单元格的值
*/
void handle(int sheetIndex, long rowIndex, List<Object> rowList);
void handle(int sheetIndex, long rowIndex, List<Object> rowCells);
/**
* 处理一个单元格的数据

View File

@ -125,7 +125,7 @@ public class ExcelSaxReadTest {
}
@Override
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
}
}
@ -143,7 +143,7 @@ public class ExcelSaxReadTest {
}
@Override
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
}
}
);