mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
9eb982b7a6
commit
2ee6c0356a
@ -5,6 +5,7 @@ import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.file.FileSystemUtil;
|
||||
import cn.hutool.core.io.file.PathUtil;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
@ -172,7 +173,7 @@ public class ZipUtil {
|
||||
* @throws UtilException IO异常
|
||||
*/
|
||||
public static File zip(final File srcFile, final Charset charset) throws UtilException {
|
||||
final File zipFile = FileUtil.file(srcFile.getParentFile(), FileUtil.mainName(srcFile) + ".zip");
|
||||
final File zipFile = FileUtil.file(srcFile.getParentFile(), FileNameUtil.mainName(srcFile) + ".zip");
|
||||
zip(zipFile, charset, false, srcFile);
|
||||
return zipFile;
|
||||
}
|
||||
@ -468,7 +469,7 @@ public class ZipUtil {
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public static File unzip(final File zipFile, final Charset charset) throws UtilException {
|
||||
final File destDir = FileUtil.file(zipFile.getParentFile(), FileUtil.mainName(zipFile));
|
||||
final File destDir = FileUtil.file(zipFile.getParentFile(), FileNameUtil.mainName(zipFile));
|
||||
return unzip(zipFile, destDir, charset);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.File;
|
||||
@ -139,10 +140,10 @@ public class FileTypeUtil {
|
||||
String typeName = getType(in,isExact);
|
||||
if (null == typeName) {
|
||||
// 未成功识别类型,扩展名辅助识别
|
||||
typeName = FileUtil.extName(filename);
|
||||
typeName = FileNameUtil.extName(filename);
|
||||
} else if ("zip".equals(typeName)) {
|
||||
// zip可能为docx、xlsx、pptx、jar、war、ofd等格式,扩展名辅助判断
|
||||
final String extName = FileUtil.extName(filename);
|
||||
final String extName = FileNameUtil.extName(filename);
|
||||
if ("docx".equalsIgnoreCase(extName)) {
|
||||
typeName = "docx";
|
||||
} else if ("xlsx".equalsIgnoreCase(extName)) {
|
||||
@ -160,7 +161,7 @@ public class FileTypeUtil {
|
||||
}
|
||||
} else if ("jar".equals(typeName)) {
|
||||
// wps编辑过的.xlsx文件与.jar的开头相同,通过扩展名判断
|
||||
final String extName = FileUtil.extName(filename);
|
||||
final String extName = FileNameUtil.extName(filename);
|
||||
if ("xlsx".equalsIgnoreCase(extName)) {
|
||||
typeName = "xlsx";
|
||||
} else if ("docx".equalsIgnoreCase(extName)) {
|
||||
|
@ -660,11 +660,10 @@ public class FileUtil extends PathUtil {
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* @param fullFileOrDirPath 文件或者目录的路径
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static boolean del(final String fullFileOrDirPath) throws IORuntimeException {
|
||||
return del(file(fullFileOrDirPath));
|
||||
public static void del(final String fullFileOrDirPath) throws IORuntimeException {
|
||||
del(file(fullFileOrDirPath));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -672,42 +671,13 @@ public class FileUtil extends PathUtil {
|
||||
* 注意:删除文件夹时不会判断文件夹是否为空,如果不空则递归删除子文件或文件夹<br>
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* <p>
|
||||
* 从5.7.6开始,删除文件使用{@link Files#delete(Path)}代替 {@link File#delete()}<br>
|
||||
* 因为前者遇到文件被占用等原因时,抛出异常,而非返回false,异常会指明具体的失败原因。
|
||||
* </p>
|
||||
*
|
||||
* @param file 文件对象
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
* @see Files#delete(Path)
|
||||
*/
|
||||
public static boolean del(final File file) throws IORuntimeException {
|
||||
if (file == null || false == file.exists()) {
|
||||
// 如果文件不存在或已被删除,此处返回true表示删除成功
|
||||
return true;
|
||||
}
|
||||
|
||||
if (file.isDirectory()) {
|
||||
// 清空目录下所有文件和目录
|
||||
final boolean isOk = clean(file);
|
||||
if (false == isOk) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 删除文件或清空后的目录
|
||||
final Path path = file.toPath();
|
||||
try {
|
||||
delFile(path);
|
||||
} catch (final DirectoryNotEmptyException e) {
|
||||
// 遍历清空目录没有成功,此时补充删除一次(可能存在部分软链)
|
||||
del(path);
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
public static void del(final File file) throws IORuntimeException {
|
||||
Assert.notNull(file, "File must be not null!");
|
||||
PathUtil.del(file.toPath());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -716,12 +686,10 @@ public class FileUtil extends PathUtil {
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* @param dirPath 文件夹路径
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 4.0.8
|
||||
*/
|
||||
public static boolean clean(final String dirPath) throws IORuntimeException {
|
||||
return clean(file(dirPath));
|
||||
public static void clean(final String dirPath) throws IORuntimeException {
|
||||
clean(file(dirPath));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -730,52 +698,11 @@ public class FileUtil extends PathUtil {
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* @param directory 文件夹
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public static boolean clean(final File directory) throws IORuntimeException {
|
||||
if (directory == null || directory.exists() == false || false == directory.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final File[] files = directory.listFiles();
|
||||
if (null != files) {
|
||||
for (final File childFile : files) {
|
||||
if (false == del(childFile)) {
|
||||
// 删除一个出错则本次删除任务失败
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理空文件夹<br>
|
||||
* 此方法用于递归删除空的文件夹,不删除文件<br>
|
||||
* 如果传入的文件夹本身就是空的,删除这个文件夹
|
||||
*
|
||||
* @param directory 文件夹
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 4.5.5
|
||||
*/
|
||||
public static boolean cleanEmpty(final File directory) throws IORuntimeException {
|
||||
if (directory == null || false == directory.exists() || false == directory.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final File[] files = directory.listFiles();
|
||||
if (ArrayUtil.isEmpty(files)) {
|
||||
// 空文件夹则删除之
|
||||
return directory.delete();
|
||||
}
|
||||
|
||||
for (final File childFile : files) {
|
||||
cleanEmpty(childFile);
|
||||
}
|
||||
return true;
|
||||
public static void clean(final File directory) throws IORuntimeException {
|
||||
Assert.notNull(directory, "File must be not null!");
|
||||
PathUtil.clean(directory.toPath());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -978,7 +905,7 @@ public class FileUtil extends PathUtil {
|
||||
* </pre>
|
||||
*
|
||||
* @param src 源文件
|
||||
* @param target 目标文件或目录,目标不存在会自动创建(目录、文件都创建)
|
||||
* @param target 目标文件或目录,目标不存在会自动创建(目录、文件都创建)
|
||||
* @param isOverride 是否覆盖目标文件
|
||||
* @return 目标目录或文件
|
||||
* @throws IORuntimeException IO异常
|
||||
@ -1013,9 +940,9 @@ public class FileUtil extends PathUtil {
|
||||
Assert.notNull(src, "Src file must be not null!");
|
||||
Assert.notNull(target, "target file must be not null!");
|
||||
return PathUtil.copyContent(
|
||||
src.toPath(),
|
||||
target.toPath(),
|
||||
isOverride ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{})
|
||||
src.toPath(),
|
||||
target.toPath(),
|
||||
isOverride ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{})
|
||||
.toFile();
|
||||
}
|
||||
|
||||
@ -1086,7 +1013,7 @@ public class FileUtil extends PathUtil {
|
||||
*/
|
||||
public static File rename(final File file, String newName, final boolean isRetainExt, final boolean isOverride) {
|
||||
if (isRetainExt) {
|
||||
final String extName = FileUtil.extName(file);
|
||||
final String extName = FileNameUtil.extName(file);
|
||||
if (StrUtil.isNotBlank(extName)) {
|
||||
newName = newName.concat(".").concat(extName);
|
||||
}
|
||||
@ -1518,129 +1445,6 @@ public class FileUtil extends PathUtil {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------- name start
|
||||
|
||||
/**
|
||||
* 返回文件名
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 文件名
|
||||
* @see FileNameUtil#getName(File)
|
||||
* @since 4.1.13
|
||||
*/
|
||||
public static String getName(final File file) {
|
||||
return FileNameUtil.getName(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件名<br>
|
||||
* <pre>
|
||||
* "d:/test/aaa" 返回 "aaa"
|
||||
* "/test/aaa.jpg" 返回 "aaa.jpg"
|
||||
* </pre>
|
||||
*
|
||||
* @param filePath 文件
|
||||
* @return 文件名
|
||||
* @see FileNameUtil#getName(String)
|
||||
* @since 4.1.13
|
||||
*/
|
||||
public static String getName(final String filePath) {
|
||||
return FileNameUtil.getName(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件后缀名,扩展名不带“.”
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 扩展名
|
||||
* @see FileNameUtil#getSuffix(File)
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public static String getSuffix(final File file) {
|
||||
return FileNameUtil.getSuffix(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文件后缀名,扩展名不带“.”
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @return 扩展名
|
||||
* @see FileNameUtil#getSuffix(String)
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public static String getSuffix(final String fileName) {
|
||||
return FileNameUtil.getSuffix(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主文件名
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 主文件名
|
||||
* @see FileNameUtil#getPrefix(File)
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public static String getPrefix(final File file) {
|
||||
return FileNameUtil.getPrefix(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主文件名
|
||||
*
|
||||
* @param fileName 完整文件名
|
||||
* @return 主文件名
|
||||
* @see FileNameUtil#getPrefix(String)
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public static String getPrefix(final String fileName) {
|
||||
return FileNameUtil.getPrefix(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主文件名
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 主文件名
|
||||
* @see FileNameUtil#mainName(File)
|
||||
*/
|
||||
public static String mainName(final File file) {
|
||||
return FileNameUtil.mainName(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主文件名
|
||||
*
|
||||
* @param fileName 完整文件名
|
||||
* @return 主文件名
|
||||
* @see FileNameUtil#mainName(String)
|
||||
*/
|
||||
public static String mainName(final String fileName) {
|
||||
return FileNameUtil.mainName(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件扩展名(后缀名),扩展名不带“.”
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 扩展名
|
||||
* @see FileNameUtil#extName(File)
|
||||
*/
|
||||
public static String extName(final File file) {
|
||||
return FileNameUtil.extName(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文件的扩展名(后缀名),扩展名不带“.”
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @return 扩展名
|
||||
* @see FileNameUtil#extName(String)
|
||||
*/
|
||||
public static String extName(final String fileName) {
|
||||
return FileNameUtil.extName(fileName);
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------- name end
|
||||
|
||||
/**
|
||||
* 判断文件路径是否有指定后缀,忽略大小写<br>
|
||||
* 常用语判断扩展名
|
||||
@ -2918,30 +2722,6 @@ public class FileUtil extends PathUtil {
|
||||
return FileWriter.of(file, charset).writeLines(lines, lineSeparator, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除文件名中的在Windows下不支持的非法字符,包括: \ / : * ? " < > |
|
||||
*
|
||||
* @param fileName 文件名(必须不包括路径,否则路径符将被替换)
|
||||
* @return 清理后的文件名
|
||||
* @see FileNameUtil#cleanInvalid(String)
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public static String cleanInvalid(final String fileName) {
|
||||
return FileNameUtil.cleanInvalid(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件名中是否包含在Windows下不支持的非法字符,包括: \ / : * ? " < > |
|
||||
*
|
||||
* @param fileName 文件名(必须不包括路径,否则路径符将被替换)
|
||||
* @return 是否包含非法字符
|
||||
* @see FileNameUtil#containsInvalid(String)
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public static boolean containsInvalid(final String fileName) {
|
||||
return FileNameUtil.containsInvalid(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Web项目下的web root路径<br>
|
||||
* 原理是首先获取ClassPath路径,由于在web项目中ClassPath位于 WEB-INF/classes/下,故向上获取两级目录即可。
|
||||
|
104
hutool-core/src/main/java/cn/hutool/core/io/file/PathDeleter.java
Executable file
104
hutool-core/src/main/java/cn/hutool/core/io/file/PathDeleter.java
Executable file
@ -0,0 +1,104 @@
|
||||
package cn.hutool.core.io.file;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.file.visitor.DelVisitor;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 文件删除封装
|
||||
*
|
||||
* @author looly
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class PathDeleter {
|
||||
|
||||
/**
|
||||
* 创建文件或目录移动器
|
||||
*
|
||||
* @param src 源文件或目录
|
||||
* @return {@code PathMover}
|
||||
*/
|
||||
public static PathDeleter of(final Path src) {
|
||||
return new PathDeleter(src);
|
||||
}
|
||||
|
||||
private final Path path;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param path 文件或目录,不能为{@code null}且必须存在
|
||||
*/
|
||||
public PathDeleter(final Path path) {
|
||||
this.path = Assert.notNull(path, "Path must be not null !");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件或者文件夹,不追踪软链<br>
|
||||
* 注意:删除文件夹时不会判断文件夹是否为空,如果不空则递归删除子文件或文件夹<br>
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public void del() throws IORuntimeException {
|
||||
final Path path = this.path;
|
||||
if (Files.notExists(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PathUtil.isDirectory(path)) {
|
||||
_del(path);
|
||||
} else {
|
||||
delFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空目录
|
||||
*/
|
||||
public void clean() {
|
||||
try (final Stream<Path> list = Files.list(this.path)){
|
||||
list.forEach(PathUtil::del);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除目录
|
||||
*
|
||||
* @param path 目录路径
|
||||
*/
|
||||
private static void _del(final Path path) {
|
||||
try {
|
||||
Files.walkFileTree(path, DelVisitor.INSTANCE);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件或空目录,不追踪软链
|
||||
*
|
||||
* @param path 文件对象
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.7.7
|
||||
*/
|
||||
private static void delFile(final Path path) throws IORuntimeException {
|
||||
try {
|
||||
Files.delete(path);
|
||||
} catch (final IOException e) {
|
||||
if (e instanceof AccessDeniedException) {
|
||||
// 可能遇到只读文件,无法删除.使用 file 方法删除
|
||||
if (path.toFile().delete()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -67,7 +67,7 @@ public class PathMover {
|
||||
* <li>如果src和target为同一文件或目录,直接返回target。</li>
|
||||
* <li>如果src为文件,target为目录,则移动到目标目录下,存在同名文件则按照是否覆盖参数执行。</li>
|
||||
* <li>如果src为文件,target为文件,则按照是否覆盖参数执行。</li>
|
||||
* <li>如果src为文件,target为不存在的路径,则重命名源文件到目标指定的文件,如moveContent("/a/b", "/c/d"), d不存在,则b变成d。</li>
|
||||
* <li>如果src为文件,target为不存在的路径,则重命名源文件到目标指定的文件,如move("/a/b", "/c/d"), d不存在,则b变成d。</li>
|
||||
* <li>如果src为目录,target为文件,抛出{@link IllegalArgumentException}</li>
|
||||
* <li>如果src为目录,target为目录,则将源目录及其内容移动到目标路径目录中,如move("/a/b", "/c/d"),结果为"/c/d/b"</li>
|
||||
* <li>如果src为目录,target为不存在的路径,则重命名src到target,如move("/a/b", "/c/d"),结果为"/c/d/",相当于b重命名为d</li>
|
||||
|
@ -2,7 +2,6 @@ package cn.hutool.core.io.file;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.visitor.DelVisitor;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
@ -127,25 +126,11 @@ public class PathUtil {
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* @param path 文件对象
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 4.4.2
|
||||
*/
|
||||
public static boolean del(final Path path) throws IORuntimeException {
|
||||
if (Files.notExists(path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isDirectory(path)) {
|
||||
Files.walkFileTree(path, DelVisitor.INSTANCE);
|
||||
} else {
|
||||
delFile(path);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
public static void del(final Path path) throws IORuntimeException {
|
||||
PathDeleter.of(path).del();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,11 +139,7 @@ public class PathUtil {
|
||||
* @param path 目录路径
|
||||
*/
|
||||
public static void clean(final Path path) {
|
||||
try {
|
||||
Files.walkFileTree(path, DelVisitor.INSTANCE);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
PathDeleter.of(path).clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -617,22 +598,4 @@ public class PathUtil {
|
||||
}
|
||||
return path.getFileName().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件或空目录,不追踪软链
|
||||
*
|
||||
* @param path 文件对象
|
||||
* @throws IOException IO异常
|
||||
* @since 5.7.7
|
||||
*/
|
||||
protected static void delFile(final Path path) throws IOException {
|
||||
try {
|
||||
Files.delete(path);
|
||||
} catch (final AccessDeniedException e) {
|
||||
// 可能遇到只读文件,无法删除.使用 file 方法删除
|
||||
if (false == path.toFile().delete()) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.io.file.visitor;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.io.resource;
|
||||
|
||||
import cn.hutool.core.classloader.ClassLoaderUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
@ -67,7 +68,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
final String path = normalizePath(pathBaseClassLoader);
|
||||
this.path = path;
|
||||
this.name = StrUtil.isBlank(path) ? null : FileUtil.getName(path);
|
||||
this.name = StrUtil.isBlank(path) ? null : FileNameUtil.getName(path);
|
||||
|
||||
this.classLoader = ObjUtil.defaultIfNull(classLoader, ClassLoaderUtil::getClassLoader);
|
||||
this.clazz = clazz;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io.resource;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
@ -50,7 +51,7 @@ public class UrlResource implements Resource, Serializable{
|
||||
if(null != url && URLUtil.URL_PROTOCOL_FILE.equals(url.getProtocol())){
|
||||
this.lastModified = FileUtil.file(url).lastModified();
|
||||
}
|
||||
this.name = ObjUtil.defaultIfNull(name, () -> (null != url ? FileUtil.getName(url.getPath()) : null));
|
||||
this.name = ObjUtil.defaultIfNull(name, () -> (null != url ? FileNameUtil.getName(url.getPath()) : null));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------- Constructor end
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.net.multipart;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
@ -247,7 +248,7 @@ public class UploadFile {
|
||||
return isAllow;
|
||||
}
|
||||
|
||||
final String fileNameExt = FileUtil.extName(this.getFileName());
|
||||
final String fileNameExt = FileNameUtil.extName(this.getFileName());
|
||||
for (final String fileExtension : setting.fileExts) {
|
||||
if (fileNameExt.equalsIgnoreCase(fileExtension)) {
|
||||
return isAllow;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.file.LineSeparator;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
@ -53,22 +54,6 @@ public class FileUtilTest {
|
||||
FileUtil.touch("d:\\tea\\a.jpg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void delTest() {
|
||||
// 删除一个不存在的文件,应返回true
|
||||
final boolean result = FileUtil.del("e:/Hutool_test_3434543533409843.txt");
|
||||
Assert.assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void delTest2() {
|
||||
// 删除一个不存在的文件,应返回true
|
||||
final boolean result = FileUtil.del(Paths.get("e:/Hutool_test_3434543533409843.txt"));
|
||||
Assert.assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void renameTest() {
|
||||
@ -317,61 +302,61 @@ public class FileUtilTest {
|
||||
@Test
|
||||
public void getNameTest() {
|
||||
String path = "d:\\aaa\\bbb\\cc\\ddd\\";
|
||||
String name = FileUtil.getName(path);
|
||||
String name = FileNameUtil.getName(path);
|
||||
Assert.assertEquals("ddd", name);
|
||||
|
||||
path = "d:\\aaa\\bbb\\cc\\ddd.jpg";
|
||||
name = FileUtil.getName(path);
|
||||
name = FileNameUtil.getName(path);
|
||||
Assert.assertEquals("ddd.jpg", name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mainNameTest() {
|
||||
String path = "d:\\aaa\\bbb\\cc\\ddd\\";
|
||||
String mainName = FileUtil.mainName(path);
|
||||
String mainName = FileNameUtil.mainName(path);
|
||||
Assert.assertEquals("ddd", mainName);
|
||||
|
||||
path = "d:\\aaa\\bbb\\cc\\ddd";
|
||||
mainName = FileUtil.mainName(path);
|
||||
mainName = FileNameUtil.mainName(path);
|
||||
Assert.assertEquals("ddd", mainName);
|
||||
|
||||
path = "d:\\aaa\\bbb\\cc\\ddd.jpg";
|
||||
mainName = FileUtil.mainName(path);
|
||||
mainName = FileNameUtil.mainName(path);
|
||||
Assert.assertEquals("ddd", mainName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extNameTest() {
|
||||
String path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\ddd\\" : "~/Desktop/hutool/ddd/";
|
||||
String mainName = FileUtil.extName(path);
|
||||
String mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\ddd" : "~/Desktop/hutool/ddd";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\ddd.jpg" : "~/Desktop/hutool/ddd.jpg";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("jpg", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.xlsx" : "~/Desktop/hutool/fff.xlsx";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("xlsx", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.gz" : "~/Desktop/hutool/fff.tar.gz";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("tar.gz", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.Z" : "~/Desktop/hutool/fff.tar.Z";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("tar.Z", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.bz2" : "~/Desktop/hutool/fff.tar.bz2";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("tar.bz2", mainName);
|
||||
|
||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.xz" : "~/Desktop/hutool/fff.tar.xz";
|
||||
mainName = FileUtil.extName(path);
|
||||
mainName = FileNameUtil.extName(path);
|
||||
Assert.assertEquals("tar.xz", mainName);
|
||||
}
|
||||
|
||||
@ -445,10 +430,10 @@ public class FileUtilTest {
|
||||
Assert.assertTrue(nullDirTempFile.exists());
|
||||
|
||||
final File suffixDirTempFile = FileUtil.createTempFile(".xlsx",true);
|
||||
Assert.assertEquals("xlsx", FileUtil.getSuffix(suffixDirTempFile));
|
||||
Assert.assertEquals("xlsx", FileNameUtil.getSuffix(suffixDirTempFile));
|
||||
|
||||
final File prefixDirTempFile = FileUtil.createTempFile("prefix",".xlsx",true);
|
||||
Assert.assertTrue(FileUtil.getPrefix(prefixDirTempFile).startsWith("prefix"));
|
||||
Assert.assertTrue(FileNameUtil.getPrefix(prefixDirTempFile).startsWith("prefix"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.io.file;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@ -11,6 +12,7 @@ import java.nio.file.Paths;
|
||||
public class PathCopyTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copySameFileTest() {
|
||||
final Path path = Paths.get("d:/test/dir1/test1.txt");
|
||||
//src路径和target路径相同时,不执行操作
|
||||
@ -20,6 +22,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copySameDirTest() {
|
||||
final Path path = Paths.get("d:/test/dir1");
|
||||
//src路径和target路径相同时,不执行操作
|
||||
@ -29,6 +32,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileToDirTest() {
|
||||
// src为文件,target为已存在目录,则拷贝到目录下,文件名不变。
|
||||
PathUtil.copy(
|
||||
@ -37,6 +41,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileToPathNotExistTest() {
|
||||
// src为文件,target为不存在路径,则目标以文件对待(自动创建父级目录)
|
||||
// 相当于拷贝后重命名
|
||||
@ -46,6 +51,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileToFileTest() {
|
||||
//src为文件,target是一个已存在的文件,则当{@link CopyOption}设为覆盖时会被覆盖,默认不覆盖。
|
||||
PathUtil.copy(
|
||||
@ -54,6 +60,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyDirToDirTest() {
|
||||
//src为目录,target为已存在目录,整个src目录连同其目录拷贝到目标目录中
|
||||
PathUtil.copy(
|
||||
@ -62,6 +69,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyDirToPathNotExistTest() {
|
||||
//src为目录,target为不存在路径,则自动创建目标为新目录,整个src目录连同其目录拷贝到目标目录中
|
||||
PathUtil.copy(
|
||||
@ -70,6 +78,7 @@ public class PathCopyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyDirToFileTest() {
|
||||
//src为目录,target为文件,抛出IllegalArgumentException
|
||||
PathUtil.copy(
|
||||
|
28
hutool-core/src/test/java/cn/hutool/core/io/file/PathDeleterTest.java
Executable file
28
hutool-core/src/test/java/cn/hutool/core/io/file/PathDeleterTest.java
Executable file
@ -0,0 +1,28 @@
|
||||
package cn.hutool.core.io.file;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class PathDeleterTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void delFileTest() {
|
||||
FileUtil.touch("d:/test/exist.txt");
|
||||
PathUtil.del(Paths.get("d:/test/exist.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void delDirTest() {
|
||||
PathUtil.del(Paths.get("d:/test/dir1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void cleanDirTest() {
|
||||
PathUtil.clean(Paths.get("d:/test/dir1"));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package cn.hutool.extra.ftp;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
@ -19,6 +20,9 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class AbstractFtp implements Closeable {
|
||||
|
||||
/**
|
||||
* 默认编码
|
||||
*/
|
||||
public static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;
|
||||
|
||||
protected FtpConfig ftpConfig;
|
||||
@ -113,7 +117,7 @@ public abstract class AbstractFtp implements Closeable {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String fileName = FileUtil.getName(path);
|
||||
final String fileName = FileNameUtil.getName(path);
|
||||
if (".".equals(fileName) || "..".equals(fileName)) {
|
||||
return false;
|
||||
}
|
||||
@ -210,20 +214,20 @@ public abstract class AbstractFtp implements Closeable {
|
||||
* 来自:<a href="https://gitee.com/dromara/hutool/pulls/407">https://gitee.com/dromara/hutool/pulls/407</a><br>
|
||||
* 此方法原理是先在目标文件同级目录下创建临时文件,下载之,等下载完毕后重命名,避免因下载错误导致的文件不完整。
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @param outFile 输出文件或目录
|
||||
* @param path 文件路径
|
||||
* @param outFile 输出文件或目录
|
||||
* @param tempFileSuffix 临时文件后缀,默认".temp"
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public void download(final String path, File outFile, String tempFileSuffix) {
|
||||
if(StrUtil.isBlank(tempFileSuffix)){
|
||||
if (StrUtil.isBlank(tempFileSuffix)) {
|
||||
tempFileSuffix = ".temp";
|
||||
} else {
|
||||
tempFileSuffix = StrUtil.addPrefixIfNot(tempFileSuffix, StrUtil.DOT);
|
||||
}
|
||||
|
||||
// 目标文件真实名称
|
||||
final String fileName = outFile.isDirectory() ? FileUtil.getName(path) : outFile.getName();
|
||||
final String fileName = outFile.isDirectory() ? FileNameUtil.getName(path) : outFile.getName();
|
||||
// 临时文件名称
|
||||
final String tempFileName = fileName + tempFileSuffix;
|
||||
|
||||
|
@ -3,6 +3,7 @@ package cn.hutool.extra.ftp;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
@ -440,7 +441,7 @@ public class Ftp extends AbstractFtp {
|
||||
@Override
|
||||
public boolean delFile(final String path) throws IORuntimeException {
|
||||
final String pwd = pwd();
|
||||
final String fileName = FileUtil.getName(path);
|
||||
final String fileName = FileNameUtil.getName(path);
|
||||
final String dir = StrUtil.removeSuffix(path, fileName);
|
||||
if (false == cd(dir)) {
|
||||
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
|
||||
@ -622,7 +623,7 @@ public class Ftp extends AbstractFtp {
|
||||
*/
|
||||
@Override
|
||||
public void download(final String path, final File outFile) {
|
||||
final String fileName = FileUtil.getName(path);
|
||||
final String fileName = FileNameUtil.getName(path);
|
||||
final String dir = StrUtil.removeSuffix(path, fileName);
|
||||
download(dir, fileName, outFile);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||
import org.apache.hc.core5.http.ClassicHttpResponse;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
|
||||
@ -57,9 +58,9 @@ public class HttpClient5Engine implements ClientEngine {
|
||||
initEngine();
|
||||
|
||||
final ClassicHttpRequest request = buildRequest(message);
|
||||
final CloseableHttpResponse response;
|
||||
final ClassicHttpResponse response;
|
||||
try {
|
||||
response = this.engine.execute(request);
|
||||
response = this.engine.executeOpen(null, request, null);
|
||||
} catch (final IOException e) {
|
||||
throw new HttpException(e);
|
||||
}
|
||||
@ -91,6 +92,7 @@ public class HttpClient5Engine implements ClientEngine {
|
||||
|
||||
final int connectionTimeout = this.config.getConnectionTimeout();
|
||||
if(connectionTimeout > 0){
|
||||
// TODO 细化替换
|
||||
builder.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
|
||||
builder.setConnectionRequestTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
@ -103,8 +105,8 @@ public class HttpClient5Engine implements ClientEngine {
|
||||
}
|
||||
|
||||
final HttpClientBuilder builder = HttpClients.custom()
|
||||
// 设置默认头信息
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
// 设置默认头信息
|
||||
.setDefaultHeaders(toHeaderList(GlobalHeaders.INSTANCE.headers()));
|
||||
|
||||
// TODO 设置代理
|
||||
|
@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.http.HttpException;
|
||||
import cn.hutool.http.client.Response;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||
import org.apache.hc.core5.http.ClassicHttpResponse;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.ParseException;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
@ -30,7 +31,7 @@ public class HttpClient5Response implements Response {
|
||||
/**
|
||||
* HttpClient的响应对象
|
||||
*/
|
||||
private final CloseableHttpResponse rawRes;
|
||||
private final ClassicHttpResponse rawRes;
|
||||
/**
|
||||
* 请求时的默认编码
|
||||
*/
|
||||
@ -43,7 +44,7 @@ public class HttpClient5Response implements Response {
|
||||
* @param rawRes {@link CloseableHttpResponse}
|
||||
* @param requestCharset 请求时的编码
|
||||
*/
|
||||
public HttpClient5Response(final CloseableHttpResponse rawRes, final Charset requestCharset) {
|
||||
public HttpClient5Response(final ClassicHttpResponse rawRes, final Charset requestCharset) {
|
||||
this.rawRes = rawRes;
|
||||
this.requestCharset = requestCharset;
|
||||
}
|
||||
|
@ -7,25 +7,13 @@ import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.http.HttpGlobalConfig;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.http.client.HeaderOperation;
|
||||
import cn.hutool.http.client.Request;
|
||||
import cn.hutool.http.client.Response;
|
||||
import cn.hutool.http.client.engine.ClientEngineFactory;
|
||||
import cn.hutool.http.client.engine.jdk.HttpBase;
|
||||
import cn.hutool.http.meta.Header;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPBodyElement;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.soap.*;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -14,13 +14,13 @@ import java.util.Map;
|
||||
*/
|
||||
public class Issue2749Test {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Ignore
|
||||
public void jsonObjectTest() {
|
||||
final Map<String, Object> map = new HashMap<>(1, 1f);
|
||||
Map<String, Object> node = map;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
//noinspection unchecked
|
||||
node = (Map<String, Object>) node.computeIfAbsent("a", k -> new HashMap<String, Object>(1, 1f));
|
||||
}
|
||||
node.put("a", 1);
|
||||
|
@ -3,6 +3,7 @@ package cn.hutool.poi.word;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.poi.exceptions.POIException;
|
||||
@ -158,7 +159,7 @@ public class Word07Writer implements Closeable {
|
||||
*/
|
||||
public Word07Writer addPicture(final File picFile, final int width, final int height) {
|
||||
final String fileName = picFile.getName();
|
||||
final String extName = FileUtil.extName(fileName).toUpperCase();
|
||||
final String extName = FileNameUtil.extName(fileName).toUpperCase();
|
||||
PicType picType;
|
||||
try {
|
||||
picType = PicType.valueOf(extName);
|
||||
|
@ -52,7 +52,7 @@ public class BigExcelWriteTest {
|
||||
}
|
||||
|
||||
final String filePath = "e:/bigWriteTest.xlsx";
|
||||
FileUtil.del(filePath);
|
||||
FileUtil.del(FileUtil.file(filePath));
|
||||
// 通过工具类创建writer
|
||||
final BigExcelWriter writer = ExcelUtil.getBigWriter(filePath);
|
||||
|
||||
@ -118,7 +118,7 @@ public class BigExcelWriteTest {
|
||||
|
||||
// 通过工具类创建writer
|
||||
final String path = "e:/bigWriteMapTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final BigExcelWriter writer = ExcelUtil.getBigWriter(path);
|
||||
|
||||
//设置内容字体
|
||||
@ -148,7 +148,7 @@ public class BigExcelWriteTest {
|
||||
|
||||
// 通过工具类创建writer
|
||||
final String path = "e:/bigWriteMapTest2.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final BigExcelWriter writer = ExcelUtil.getBigWriter(path);
|
||||
|
||||
// 一次性写出内容,使用默认样式
|
||||
@ -177,7 +177,7 @@ public class BigExcelWriteTest {
|
||||
final List<cn.hutool.poi.excel.TestBean> rows = ListUtil.of(bean1, bean2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "e:/bigWriteBeanTest.xlsx";
|
||||
FileUtil.del(file);
|
||||
FileUtil.del(FileUtil.file(file));
|
||||
final BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||
//自定义标题
|
||||
writer.addHeaderAlias("name", "姓名");
|
||||
@ -197,7 +197,7 @@ public class BigExcelWriteTest {
|
||||
@Ignore
|
||||
public void writeCellValueTest() {
|
||||
final String path = "d:/test/cellValueTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final BigExcelWriter writer = new BigExcelWriter(path);
|
||||
writer.writeCellValue(3, 5, "aaa");
|
||||
writer.close();
|
||||
@ -210,7 +210,7 @@ public class BigExcelWriteTest {
|
||||
final Map<String, ?> map2 = MapUtil.of("id", "123457");
|
||||
final List<?> data = Arrays.asList(map1, map2);
|
||||
final String destFilePath = "d:/test/closeTest.xlsx";//略
|
||||
FileUtil.del(destFilePath);
|
||||
FileUtil.del(FileUtil.file(destFilePath));
|
||||
try (final ExcelWriter writer = ExcelUtil.getBigWriter(destFilePath)) {
|
||||
writer.write(data).flush();
|
||||
}
|
||||
@ -221,7 +221,7 @@ public class BigExcelWriteTest {
|
||||
public void issue1210() {
|
||||
// 通过工具类创建writer
|
||||
final String path = "d:/test/issue1210.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final BigExcelWriter writer = ExcelUtil.getBigWriter(path);
|
||||
writer.addHeaderAlias("id", "SN");
|
||||
writer.addHeaderAlias("userName", "User Name");
|
||||
|
@ -147,7 +147,7 @@ public class ExcelWriteTest {
|
||||
}
|
||||
|
||||
final String filePath = "d:/test/writeTest.xlsx";
|
||||
FileUtil.del(filePath);
|
||||
FileUtil.del(FileUtil.file(filePath));
|
||||
// 通过工具类创建writer
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(filePath);
|
||||
// 通过构造方法创建writer
|
||||
@ -294,7 +294,7 @@ public class ExcelWriteTest {
|
||||
|
||||
// 通过工具类创建writer
|
||||
final String path = "f:/test/writeMapWithStyleTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.setStyleSet(null);
|
||||
|
||||
@ -328,7 +328,7 @@ public class ExcelWriteTest {
|
||||
final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "d:/test/writeMapAlias.xlsx";
|
||||
FileUtil.del(file);
|
||||
FileUtil.del(FileUtil.file(file));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(file);
|
||||
// 自定义标题
|
||||
writer.addHeaderAlias("name", "姓名");
|
||||
@ -363,7 +363,7 @@ public class ExcelWriteTest {
|
||||
final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "f:/test/test_alias.xlsx";
|
||||
FileUtil.del(file);
|
||||
FileUtil.del(FileUtil.file(file));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(file);
|
||||
writer.setOnlyAlias(true);
|
||||
// 自定义标题
|
||||
@ -461,7 +461,7 @@ public class ExcelWriteTest {
|
||||
final List<cn.hutool.poi.excel.TestBean> rows = ListUtil.of(bean1, bean2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "e:/writeBeanTest.xlsx";
|
||||
FileUtil.del(file);
|
||||
FileUtil.del(FileUtil.file(file));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(file);
|
||||
// 自定义标题
|
||||
writer.addHeaderAlias("name", "姓名");
|
||||
@ -493,7 +493,7 @@ public class ExcelWriteTest {
|
||||
final List<cn.hutool.poi.excel.OrderExcel> rows = ListUtil.of(order1, order2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "f:/test/writeBeanTest2.xlsx";
|
||||
FileUtil.del(file);
|
||||
FileUtil.del(FileUtil.file(file));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(file);
|
||||
// 自定义标题
|
||||
writer.addHeaderAlias("id", "编号");
|
||||
@ -772,7 +772,7 @@ public class ExcelWriteTest {
|
||||
list.add(map2);
|
||||
|
||||
//通过工具类创建writer
|
||||
FileUtil.del("d:/test/writeTest2123.xlsx");
|
||||
FileUtil.del(FileUtil.file("d:/test/writeTest2123.xlsx"));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeTest2123.xlsx");
|
||||
writer.addHeaderAlias("xmnf", "项目年份");//1
|
||||
|
||||
@ -790,7 +790,7 @@ public class ExcelWriteTest {
|
||||
|
||||
//通过工具类创建writer
|
||||
final String path = "d:/test/mergeForDate.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.merge(0, 3, 0, 2, DateUtil.now(), false);
|
||||
writer.close();
|
||||
@ -813,7 +813,7 @@ public class ExcelWriteTest {
|
||||
public void writeFloatTest() {
|
||||
//issue https://gitee.com/dromara/hutool/issues/I43U9G
|
||||
final String path = "d:/test/floatTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.writeRow(ListUtil.view(22.9f));
|
||||
@ -825,7 +825,7 @@ public class ExcelWriteTest {
|
||||
public void writeDoubleTest() {
|
||||
// https://gitee.com/dromara/hutool/issues/I5PI5C
|
||||
final String path = "d:/test/doubleTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.disableDefaultStyle();
|
||||
|
@ -16,7 +16,7 @@ public class Issue2307Test {
|
||||
@Ignore
|
||||
public void writeTest(){
|
||||
final String filePath = "d:/test/issue2307.xlsx";
|
||||
FileUtil.del(filePath);
|
||||
FileUtil.del(FileUtil.file(filePath));
|
||||
|
||||
final List<Object> row1 = ListUtil.of("设备1", 11, 111, 1111.444, 1111.444, 1111.444, 1111.444, 119999999999999999999999999999999999999999911.444);
|
||||
final List<Object> row2 = ListUtil.of("设备2", 22, 222, 2222.555, 2222.555, 2222.555, 2222.555, 2222.555);
|
||||
|
@ -591,6 +591,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
|
||||
* @param fields lambda,不能为空
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Setting setFields(final SerSupplier<String>... fields) {
|
||||
Arrays.stream(fields).forEach(f -> set(LambdaUtil.getFieldName(f), f.get()));
|
||||
return this;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.setting.dialect;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.resource.NoResourceException;
|
||||
import cn.hutool.core.map.SafeConcurrentHashMap;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
@ -30,7 +31,7 @@ public class PropsUtil {
|
||||
*/
|
||||
public static Props get(final String name) {
|
||||
return propsMap.computeIfAbsent(name, (filePath)->{
|
||||
final String extName = FileUtil.extName(filePath);
|
||||
final String extName = FileNameUtil.extName(filePath);
|
||||
if (StrUtil.isEmpty(extName)) {
|
||||
filePath = filePath + "." + Props.EXT_NAME;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.hutool.swing.img;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.math.NumberUtil;
|
||||
@ -724,7 +725,7 @@ public class Img implements Serializable {
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public boolean write(final File targetFile) throws IORuntimeException {
|
||||
final String formatName = FileUtil.extName(targetFile);
|
||||
final String formatName = FileNameUtil.extName(targetFile);
|
||||
if (StrUtil.isNotBlank(formatName)) {
|
||||
this.targetImageType = formatName;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.codec.BaseN.Base64;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.math.NumberUtil;
|
||||
@ -119,7 +120,7 @@ public class ImgUtil {
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public static void scale(final Image srcImg, final File destFile, final float scale) throws IORuntimeException {
|
||||
Img.from(srcImg).setTargetImageType(FileUtil.extName(destFile)).scale(scale).write(destFile);
|
||||
Img.from(srcImg).setTargetImageType(FileNameUtil.extName(destFile)).scale(scale).write(destFile);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +190,7 @@ public class ImgUtil {
|
||||
*/
|
||||
public static void scale(final File srcImageFile, final File destImageFile, final int width, final int height, final Color fixedColor) throws IORuntimeException {
|
||||
Img.from(srcImageFile)//
|
||||
.setTargetImageType(FileUtil.extName(destImageFile))//
|
||||
.setTargetImageType(FileNameUtil.extName(destImageFile))//
|
||||
.scale(width, height, fixedColor)//
|
||||
.write(destImageFile);
|
||||
}
|
||||
@ -507,8 +508,8 @@ public class ImgUtil {
|
||||
Assert.notNull(destImageFile);
|
||||
Assert.isFalse(srcImageFile.equals(destImageFile), "Src file is equals to dest file!");
|
||||
|
||||
final String srcExtName = FileUtil.extName(srcImageFile);
|
||||
final String destExtName = FileUtil.extName(destImageFile);
|
||||
final String srcExtName = FileNameUtil.extName(srcImageFile);
|
||||
final String destExtName = FileNameUtil.extName(destImageFile);
|
||||
if (StrUtil.equalsIgnoreCase(srcExtName, destExtName)) {
|
||||
// 扩展名相同直接复制文件
|
||||
FileUtil.copy(srcImageFile, destImageFile, true);
|
||||
@ -1546,7 +1547,7 @@ public class ImgUtil {
|
||||
ImageOutputStream out = null;
|
||||
try {
|
||||
out = getImageOutputStream(targetFile);
|
||||
write(image, FileUtil.extName(targetFile), out);
|
||||
write(image, FileNameUtil.extName(targetFile), out);
|
||||
} finally {
|
||||
IoUtil.close(out);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user