From d89d3b8716e543d55b730e1fd1b1bba7f253c6f7 Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 16 Jun 2023 19:19:11 +0800 Subject: [PATCH] fix code --- .../core/{util => io}/ManifestUtil.java | 2 +- .../dromara/hutool/core/io/file/FileUtil.java | 22 +++++-------------- .../dromara/hutool/core/io/file/PathUtil.java | 1 - .../hutool/core/io/ManifestUtilTest.java | 1 - .../core/io/{ => file}/FileReaderTest.java | 16 +++++++++++--- .../core/io/{ => file}/FileTypeUtilTest.java | 16 +++++++++++--- .../core/io/{ => file}/FileUtilTest.java | 18 ++++++++++----- 7 files changed, 45 insertions(+), 31 deletions(-) rename hutool-core/src/main/java/org/dromara/hutool/core/{util => io}/ManifestUtil.java (99%) rename hutool-core/src/test/java/org/dromara/hutool/core/io/{ => file}/FileReaderTest.java (62%) rename hutool-core/src/test/java/org/dromara/hutool/core/io/{ => file}/FileTypeUtilTest.java (81%) rename hutool-core/src/test/java/org/dromara/hutool/core/io/{ => file}/FileUtilTest.java (96%) diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/util/ManifestUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/io/ManifestUtil.java similarity index 99% rename from hutool-core/src/main/java/org/dromara/hutool/core/util/ManifestUtil.java rename to hutool-core/src/main/java/org/dromara/hutool/core/io/ManifestUtil.java index a793bfbd9..d2e8a247e 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/util/ManifestUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/io/ManifestUtil.java @@ -10,7 +10,7 @@ * See the Mulan PSL v2 for more details. */ -package org.dromara.hutool.core.util; +package org.dromara.hutool.core.io; import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.resource.ResourceUtil; diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/io/file/FileUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/io/file/FileUtil.java index 04d7356cc..e4de318ea 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/io/file/FileUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/io/file/FileUtil.java @@ -23,7 +23,6 @@ import org.dromara.hutool.core.io.resource.ResourceUtil; import org.dromara.hutool.core.io.stream.BOMInputStream; import org.dromara.hutool.core.io.unit.DataSizeUtil; import org.dromara.hutool.core.lang.Assert; -import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.net.url.URLUtil; import org.dromara.hutool.core.reflect.ClassUtil; import org.dromara.hutool.core.regex.ReUtil; @@ -2648,25 +2647,14 @@ public class FileUtil extends PathUtil { */ public static File checkSlip(final File parentFile, final File file) throws IllegalArgumentException { if (null != parentFile && null != file) { - if (!startsWith(parentFile, file)) { - throw new IllegalArgumentException("New file is outside of the parent dir: " + file.getName()); + if (!isSub(parentFile, file)) { + throw new IllegalArgumentException(StrUtil.format( + "New file [{}] is outside of the parent dir: [{}]", file, parentFile)); } } return file; } - /** - * 检查父文件是否为文件真正的父目录 - * - * @param parentFile 父目录 - * @param file 文件 - * @return 是否为文件真正的父目录 - */ - public static boolean startsWith(final File parentFile, final File file) { - return PathUtil.toAbsNormal(parentFile.toPath()) - .startsWith(PathUtil.toAbsNormal(file.toPath())); - } - /** * 根据文件扩展名获得MimeType * @@ -2727,8 +2715,8 @@ public class FileUtil extends PathUtil { /** * 判断给定的目录是否为给定文件或文件夹的子目录 * - * @param parent 父目录 - * @param sub 子目录 + * @param parent 父目录,非空 + * @param sub 子目录,非空 * @return 子目录是否为父目录的子目录 * @since 4.5.4 */ diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/io/file/PathUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/io/file/PathUtil.java index c9791a989..fa113412f 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/io/file/PathUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/io/file/PathUtil.java @@ -14,7 +14,6 @@ package org.dromara.hutool.core.io.file; import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IoUtil; -import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.util.CharsetUtil; import java.io.*; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/io/ManifestUtilTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/io/ManifestUtilTest.java index a41dbc451..141842aa6 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/io/ManifestUtilTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/io/ManifestUtilTest.java @@ -1,6 +1,5 @@ package org.dromara.hutool.core.io; -import org.dromara.hutool.core.util.ManifestUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/io/FileReaderTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileReaderTest.java similarity index 62% rename from hutool-core/src/test/java/org/dromara/hutool/core/io/FileReaderTest.java rename to hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileReaderTest.java index d87c5cca7..d237614ad 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/io/FileReaderTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileReaderTest.java @@ -1,8 +1,18 @@ -package org.dromara.hutool.core.io; +/* + * Copyright (c) 2023 looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.dromara.hutool.core.io.file; -import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.text.StrUtil; -import org.dromara.hutool.core.io.file.FileReader; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/io/FileTypeUtilTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileTypeUtilTest.java similarity index 81% rename from hutool-core/src/test/java/org/dromara/hutool/core/io/FileTypeUtilTest.java rename to hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileTypeUtilTest.java index 98d905dc2..c7ed862cf 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/io/FileTypeUtilTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileTypeUtilTest.java @@ -1,7 +1,17 @@ -package org.dromara.hutool.core.io; +/* + * Copyright (c) 2023 looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.dromara.hutool.core.io.file; -import org.dromara.hutool.core.io.file.FileTypeUtil; -import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.io.resource.ResourceUtil; import org.dromara.hutool.core.lang.Console; import org.junit.jupiter.api.Assertions; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/io/FileUtilTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileUtilTest.java similarity index 96% rename from hutool-core/src/test/java/org/dromara/hutool/core/io/FileUtilTest.java rename to hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileUtilTest.java index 5d4649139..2a3598c67 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/io/FileUtilTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/io/file/FileUtilTest.java @@ -1,9 +1,18 @@ -package org.dromara.hutool.core.io; +/* + * Copyright (c) 2023 looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.dromara.hutool.core.io.file; import org.dromara.hutool.core.collection.ListUtil; -import org.dromara.hutool.core.io.file.FileNameUtil; -import org.dromara.hutool.core.io.file.FileUtil; -import org.dromara.hutool.core.io.file.LineSeparator; import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.util.CharsetUtil; import org.dromara.hutool.core.util.SystemUtil; @@ -460,7 +469,6 @@ public class FileUtilTest { } @Test - //@Disabled public void createTempFileTest(){ final File nullDirTempFile = FileUtil.createTempFile(); Assertions.assertTrue(nullDirTempFile.exists());