mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix FileResourceBug
This commit is contained in:
parent
d53f1ff15e
commit
662485fb2b
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.7.17 (2021-11-07)
|
# 5.7.17 (2021-11-10)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
* 【core 】 修复FileResource构造fileName参数无效问题(issue#1942@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package cn.hutool.core.io.resource;
|
package cn.hutool.core.io.resource;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
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 cn.hutool.core.util.URLUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -18,11 +20,21 @@ public class FileResource implements Resource, Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- Constructor start
|
// ----------------------------------------------------------------------- Constructor start
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*
|
*
|
||||||
|
* @param path 文件绝对路径或相对ClassPath路径,但是这个路径不能指向一个jar包中的文件
|
||||||
|
*/
|
||||||
|
public FileResource(String path) {
|
||||||
|
this(FileUtil.file(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造,文件名使用文件本身的名字,带扩展名
|
||||||
|
*
|
||||||
* @param path 文件
|
* @param path 文件
|
||||||
* @since 4.4.1
|
* @since 4.4.1
|
||||||
*/
|
*/
|
||||||
@ -31,37 +43,31 @@ public class FileResource implements Resource, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造,文件名使用文件本身的名字,带扩展名
|
||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
*/
|
*/
|
||||||
public FileResource(File file) {
|
public FileResource(File file) {
|
||||||
this(file, file.getName());
|
this(file, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @param fileName 文件名,如果为null获取文件本身的文件名
|
* @param fileName 文件名,带扩展名,如果为null获取文件本身的文件名
|
||||||
*/
|
*/
|
||||||
public FileResource(File file, String fileName) {
|
public FileResource(File file, String fileName) {
|
||||||
|
Assert.notNull(file, "File must be not null !");
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.name = ObjectUtil.defaultIfNull(fileName, file.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造
|
|
||||||
*
|
|
||||||
* @param path 文件绝对路径或相对ClassPath路径,但是这个路径不能指向一个jar包中的文件
|
|
||||||
*/
|
|
||||||
public FileResource(String path) {
|
|
||||||
this(FileUtil.file(path));
|
|
||||||
}
|
|
||||||
// ----------------------------------------------------------------------- Constructor end
|
// ----------------------------------------------------------------------- Constructor end
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.file.getName();
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,6 +95,6 @@ public class FileResource implements Resource, Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return (null == this.file) ? "null" : this.file.toString();
|
return this.file.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,12 @@ public abstract class AbstractRowHandler<T> implements RowHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
|
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
|
||||||
Assert.notNull(convertFunc);
|
Assert.notNull(convertFunc);
|
||||||
if (rowIndex < this.startRowIndex || rowIndex > this.endRowIndex) {
|
if (rowIndex < this.startRowIndex || rowIndex > this.endRowIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleData(sheetIndex, rowIndex, convertFunc.callWithRuntimeException(rowList));
|
handleData(sheetIndex, rowIndex, convertFunc.callWithRuntimeException(rowCells));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,11 +42,11 @@ public abstract class BeanRowHandler<T> extends AbstractRowHandler<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (rowIndex == this.headerRowIndex) {
|
||||||
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowList));
|
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowCells));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.handle(sheetIndex, rowIndex, rowList);
|
super.handle(sheetIndex, rowIndex, rowCells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,11 @@ public abstract class MapRowHandler extends AbstractRowHandler<Map<String, Objec
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (rowIndex == this.headerRowIndex) {
|
||||||
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowList));
|
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowCells));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.handle(sheetIndex, rowIndex, rowList);
|
super.handle(sheetIndex, rowIndex, rowCells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,9 @@ public interface RowHandler {
|
|||||||
*
|
*
|
||||||
* @param sheetIndex 当前Sheet序号
|
* @param sheetIndex 当前Sheet序号
|
||||||
* @param rowIndex 当前行号,从0开始计数
|
* @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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理一个单元格的数据
|
* 处理一个单元格的数据
|
||||||
|
@ -125,7 +125,7 @@ public class ExcelSaxReadTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public void handle(int sheetIndex, long rowIndex, List<Object> rowList) {
|
public void handle(int sheetIndex, long rowIndex, List<Object> rowCells) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user