add TlsSocketStrategyBuilder

This commit is contained in:
Looly
2024-10-03 10:47:39 +08:00
parent 33a4746dc6
commit c7e0ef67aa
11 changed files with 222 additions and 71 deletions

View File

@@ -58,7 +58,7 @@ import java.util.regex.Pattern;
*
* @author looly
*/
public class FileUtil extends PathUtil {
public class FileUtil {
/**
* 文件路径分隔符<br>
@@ -146,7 +146,7 @@ public class FileUtil extends PathUtil {
* @return 是否为空
*/
public static boolean isDirEmpty(final File dir) {
return isDirEmpty(dir.toPath());
return PathUtil.isDirEmpty(dir.toPath());
}
// region ----- loop and walk
@@ -187,7 +187,7 @@ public class FileUtil extends PathUtil {
* @since 4.6.3
*/
public static List<File> loopFiles(final File file, final int maxDepth, final FileFilter fileFilter) {
return loopFiles(file.toPath(), maxDepth, fileFilter);
return PathUtil.loopFiles(file.toPath(), maxDepth, fileFilter);
}
/**
@@ -739,7 +739,7 @@ public class FileUtil extends PathUtil {
*/
public static void del(final File file) throws IORuntimeException {
Assert.notNull(file, "File must be not null!");
del(file.toPath());
PathUtil.del(file.toPath());
}
/**
@@ -764,7 +764,7 @@ public class FileUtil extends PathUtil {
*/
public static void clean(final File directory) throws IORuntimeException {
Assert.notNull(directory, "File must be not null!");
clean(directory.toPath());
PathUtil.clean(directory.toPath());
}
/**
@@ -991,7 +991,7 @@ public class FileUtil extends PathUtil {
public static File copy(final Resource src, final File target, final boolean isOverride) throws IORuntimeException {
Assert.notNull(src, "Src file must be not null!");
Assert.notNull(target, "target file must be not null!");
return copy(
return PathUtil.copy(
src,
target.toPath(),
isOverride ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{})
@@ -1012,7 +1012,7 @@ public class FileUtil extends PathUtil {
// check
Assert.notNull(src, "Source File is null !");
Assert.notNull(target, "Target File or directory is null !");
return copy(src, target.toPath(), options).toFile();
return PathUtil.copy(src, target.toPath(), options).toFile();
}
/**
@@ -1028,7 +1028,7 @@ public class FileUtil extends PathUtil {
// check
Assert.notNull(src, "Source File is null !");
Assert.notNull(out, "Target stream is null !");
return copy(src.toPath(), out);
return PathUtil.copy(src.toPath(), out);
}
/**
@@ -1064,7 +1064,7 @@ public class FileUtil extends PathUtil {
public static File copy(final File src, final File target, final boolean isOverride) throws IORuntimeException {
Assert.notNull(src, "Src file must be not null!");
Assert.notNull(target, "target file must be not null!");
return copy(
return PathUtil.copy(
src.toPath(),
target.toPath(),
isOverride ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{})
@@ -1090,7 +1090,7 @@ public class FileUtil extends PathUtil {
public static File copyContent(final File src, final File target, final boolean isOverride) throws IORuntimeException {
Assert.notNull(src, "Src file must be not null!");
Assert.notNull(target, "target file must be not null!");
return copyContent(
return PathUtil.copyContent(
src.toPath(),
target.toPath(),
isOverride ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{})
@@ -1119,7 +1119,7 @@ public class FileUtil extends PathUtil {
public static File move(final File src, final File target, final boolean isOverride) throws IORuntimeException {
Assert.notNull(src, "Src file must be not null!");
Assert.notNull(target, "target file must be not null!");
return move(src.toPath(), target.toPath(), isOverride).toFile();
return PathUtil.move(src.toPath(), target.toPath(), isOverride).toFile();
}
/**
@@ -1170,7 +1170,7 @@ public class FileUtil extends PathUtil {
newName = newName.concat(".").concat(extName);
}
}
return rename(file.toPath(), newName, isOverride).toFile();
return PathUtil.rename(file.toPath(), newName, isOverride).toFile();
}
// region ----- getCanonicalPath and getAbsolutePath
@@ -1758,7 +1758,7 @@ public class FileUtil extends PathUtil {
if (null == file) {
return null;
}
return readBytes(file.toPath());
return PathUtil.readBytes(file.toPath());
}
/**
@@ -2170,7 +2170,7 @@ public class FileUtil extends PathUtil {
* @throws IORuntimeException IO异常
*/
public static BufferedOutputStream getOutputStream(final String path, final OpenOption... options) throws IORuntimeException {
return getOutputStream(touch(path));
return getOutputStream(touch(path), options);
}
/**
@@ -2809,7 +2809,7 @@ public class FileUtil extends PathUtil {
String contentType = URLConnection.getFileNameMap().getContentTypeFor(filePath);
if (null == contentType) {
contentType = getMimeType(Paths.get(filePath));
contentType = PathUtil.getMimeType(Paths.get(filePath));
}
return contentType;
@@ -2823,7 +2823,7 @@ public class FileUtil extends PathUtil {
* @since 4.4.2
*/
public static boolean isSymlink(final File file) {
return isSymlink(file.toPath());
return PathUtil.isSymlink(file.toPath());
}
/**
@@ -2837,7 +2837,7 @@ public class FileUtil extends PathUtil {
public static boolean isSub(final File parent, final File sub) {
Assert.notNull(parent);
Assert.notNull(sub);
return isSub(parent.toPath(), sub.toPath());
return PathUtil.isSub(parent.toPath(), sub.toPath());
}
/**

View File

@@ -16,7 +16,6 @@
package org.dromara.hutool.core.io.watch;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.io.file.PathUtil;
import org.dromara.hutool.core.io.watch.watchers.WatcherChain;
import org.dromara.hutool.core.text.CharUtil;
@@ -172,7 +171,7 @@ public class WatchMonitor extends Thread implements Closeable, Serializable {
//获取目录或文件路径
if (!PathUtil.exists(this.dir, false)) {
// 不存在的路径
final Path lastPathEle = FileUtil.getLastPathEle(this.dir);
final Path lastPathEle = PathUtil.getLastPathEle(this.dir);
if (null != lastPathEle) {
final String lastPathEleStr = lastPathEle.toString();
//带有点表示有扩展名按照未创建的文件对待。Linux下.d的为目录排除之

View File

@@ -814,7 +814,7 @@ public class BeanUtilTest {
testPojo.setTestPojo2List(new TestPojo2[]{testPojo2, testPojo3});
final BeanPath beanPath = BeanPath.of("testPojo2List.age");
final BeanPath<Object> beanPath = BeanPath.of("testPojo2List.age");
final Object o = beanPath.getValue(testPojo);
assertEquals(Integer.valueOf(2), ArrayUtil.get(o, 0));

View File

@@ -27,8 +27,6 @@ import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -197,28 +195,6 @@ public class FileUtilTest {
Assertions.assertEquals(normalize, normalize2);
}
@Test
public void subPathTest() {
final Path path = Paths.get("/aaa/bbb/ccc/ddd/eee/fff");
Path subPath = FileUtil.subPath(path, 5, 4);
Assertions.assertEquals("eee", subPath.toString());
subPath = FileUtil.subPath(path, 0, 1);
Assertions.assertEquals("aaa", subPath.toString());
subPath = FileUtil.subPath(path, 1, 0);
Assertions.assertEquals("aaa", subPath.toString());
// 负数
subPath = FileUtil.subPath(path, -1, 0);
Assertions.assertEquals("aaa/bbb/ccc/ddd/eee", subPath.toString().replace('\\', '/'));
subPath = FileUtil.subPath(path, -1, Integer.MAX_VALUE);
Assertions.assertEquals("fff", subPath.toString());
subPath = FileUtil.subPath(path, -1, path.getNameCount());
Assertions.assertEquals("fff", subPath.toString());
subPath = FileUtil.subPath(path, -2, -3);
Assertions.assertEquals("ddd", subPath.toString());
}
@Test
public void subPathTest2() {
String subPath = FileUtil.subPath("d:/aaa/bbb/", "d:/aaa/bbb/ccc/");
@@ -243,20 +219,6 @@ public class FileUtilTest {
Assertions.assertEquals("", subPath);
}
@Test
public void getPathEle() {
final Path path = Paths.get("/aaa/bbb/ccc/ddd/eee/fff");
Path ele = FileUtil.getPathEle(path, -1);
Assertions.assertEquals("fff", ele.toString());
ele = FileUtil.getPathEle(path, 0);
Assertions.assertEquals("aaa", ele.toString());
ele = FileUtil.getPathEle(path, -5);
Assertions.assertEquals("bbb", ele.toString());
ele = FileUtil.getPathEle(path, -6);
Assertions.assertEquals("aaa", ele.toString());
}
@Test
@EnabledForJreRange(max = JRE.JAVA_8)
public void listFileNamesTest() {

View File

@@ -164,4 +164,40 @@ public class PathUtilTest {
assertTrue(PathUtil.isSameFile(srcFile.toPath(), destFile.toPath()));
}
@Test
public void subPathTest() {
final Path path = Paths.get("/aaa/bbb/ccc/ddd/eee/fff");
Path subPath = PathUtil.subPath(path, 5, 4);
Assertions.assertEquals("eee", subPath.toString());
subPath = PathUtil.subPath(path, 0, 1);
Assertions.assertEquals("aaa", subPath.toString());
subPath = PathUtil.subPath(path, 1, 0);
Assertions.assertEquals("aaa", subPath.toString());
// 负数
subPath = PathUtil.subPath(path, -1, 0);
Assertions.assertEquals("aaa/bbb/ccc/ddd/eee", subPath.toString().replace('\\', '/'));
subPath = PathUtil.subPath(path, -1, Integer.MAX_VALUE);
Assertions.assertEquals("fff", subPath.toString());
subPath = PathUtil.subPath(path, -1, path.getNameCount());
Assertions.assertEquals("fff", subPath.toString());
subPath = PathUtil.subPath(path, -2, -3);
Assertions.assertEquals("ddd", subPath.toString());
}
@Test
public void getPathEleTest() {
final Path path = Paths.get("/aaa/bbb/ccc/ddd/eee/fff");
Path ele = PathUtil.getPathEle(path, -1);
assertEquals("fff", ele.toString());
ele = PathUtil.getPathEle(path, 0);
assertEquals("aaa", ele.toString());
ele = PathUtil.getPathEle(path, -5);
assertEquals("bbb", ele.toString());
ele = PathUtil.getPathEle(path, -6);
assertEquals("aaa", ele.toString());
}
}