mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
02ef612b75
commit
b1aa76411e
@ -126,8 +126,10 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 根据给定资源初始化URL
|
||||
*
|
||||
* @throws NoResourceException 资源不存在
|
||||
*/
|
||||
private void initUrl() {
|
||||
private void initUrl() throws NoResourceException{
|
||||
if (null != this.clazz) {
|
||||
super.url = this.clazz.getResource(this.path);
|
||||
} else if (null != this.classLoader) {
|
||||
|
@ -18,8 +18,8 @@ package org.dromara.hutool.core.io.resource;
|
||||
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
import org.dromara.hutool.core.net.url.UrlUtil;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
@ -75,8 +75,7 @@ public class FileResource implements Resource, Serializable {
|
||||
* @param fileName 文件名,带扩展名,如果为null获取文件本身的文件名
|
||||
*/
|
||||
public FileResource(final File file, final String fileName) {
|
||||
Assert.notNull(file, "File must be not null !");
|
||||
this.file = file;
|
||||
this.file = Assert.notNull(file, "File must be not null !");;
|
||||
this.lastModified = file.lastModified();
|
||||
this.name = ObjUtil.defaultIfNull(fileName, file::getName);
|
||||
}
|
||||
@ -100,6 +99,9 @@ public class FileResource implements Resource, Serializable {
|
||||
|
||||
@Override
|
||||
public InputStream getStream() throws NoResourceException {
|
||||
if (!exists()) {
|
||||
throw new NoResourceException("File [{}] not exist!", this.file.getAbsolutePath());
|
||||
}
|
||||
return FileUtil.getInputStream(this.file);
|
||||
}
|
||||
|
||||
@ -112,6 +114,15 @@ public class FileResource implements Resource, Serializable {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件是否存在
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
public boolean exists() {
|
||||
return this.file.exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return this.lastModified != file.lastModified();
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package org.dromara.hutool.db.config;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.convert.ConvertUtil;
|
||||
import org.dromara.hutool.core.io.resource.NoResourceException;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
@ -38,13 +39,10 @@ public class SettingConfigParser implements ConfigParser {
|
||||
|
||||
private static final String CONNECTION_PREFIX = "connection.";
|
||||
/**
|
||||
* 数据库配置文件可选路径1
|
||||
* 数据库配置文件可选路径
|
||||
*/
|
||||
private static final String DEFAULT_DB_SETTING_PATH = "config/db.setting";
|
||||
private static final String[] DEFAULT_DB_SETTING_PATHS = {"config/db.setting", "db.setting"};
|
||||
/**
|
||||
* 数据库配置文件可选路径2
|
||||
*/
|
||||
private static final String DEFAULT_DB_SETTING_PATH2 = "db.setting";
|
||||
|
||||
/**
|
||||
* 创建默认配置解析器
|
||||
@ -100,18 +98,15 @@ public class SettingConfigParser implements ConfigParser {
|
||||
* @since 5.8.0
|
||||
*/
|
||||
private static Setting createDefaultSetting() {
|
||||
Setting setting;
|
||||
try {
|
||||
setting = new Setting(DEFAULT_DB_SETTING_PATH, true);
|
||||
} catch (final NoResourceException e) {
|
||||
// 尝试ClassPath下直接读取配置文件
|
||||
for (final String settingPath : DEFAULT_DB_SETTING_PATHS) {
|
||||
try {
|
||||
setting = new Setting(DEFAULT_DB_SETTING_PATH2, true);
|
||||
} catch (final NoResourceException e2) {
|
||||
throw new NoResourceException("Default db setting [{}] or [{}] in classpath not found !", DEFAULT_DB_SETTING_PATH, DEFAULT_DB_SETTING_PATH2);
|
||||
return new Setting(settingPath, true);
|
||||
} catch (final NoResourceException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return setting;
|
||||
|
||||
throw new NoResourceException("Default db settings [{}] in classpath not found !", ArrayUtil.join(DEFAULT_DB_SETTING_PATHS, ","));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user