This commit is contained in:
Looly 2023-10-23 00:41:20 +08:00
parent da00aa3969
commit d8f02fe4cf
40 changed files with 186 additions and 162 deletions

View File

@ -15,7 +15,7 @@ package org.dromara.hutool.core.classloader;
import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.reflect.method.MethodUtil;
import java.io.File;
@ -150,7 +150,7 @@ public class JarClassLoader extends URLClassLoader {
* @since 4.4.2
*/
public JarClassLoader addURL(final File dir) {
super.addURL(URLUtil.getURL(dir));
super.addURL(UrlUtil.getURL(dir));
return this;
}

View File

@ -24,7 +24,7 @@ import org.dromara.hutool.core.io.resource.Resource;
import org.dromara.hutool.core.io.stream.FastByteArrayOutputStream;
import org.dromara.hutool.core.io.stream.LimitedInputStream;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.CharUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ByteUtil;
@ -1000,11 +1000,11 @@ public class ZipUtil {
public static JarFile ofJar(String jarFileUrl) throws IORuntimeException{
Assert.notBlank(jarFileUrl, "Jar file url is blank!");
if(jarFileUrl.startsWith(URLUtil.FILE_URL_PREFIX)){
if(jarFileUrl.startsWith(UrlUtil.FILE_URL_PREFIX)){
try{
jarFileUrl = URLUtil.toURI(jarFileUrl).getSchemeSpecificPart();
jarFileUrl = UrlUtil.toURI(jarFileUrl).getSchemeSpecificPart();
} catch (final HutoolException e){
jarFileUrl = jarFileUrl.substring(URLUtil.FILE_URL_PREFIX.length());
jarFileUrl = jarFileUrl.substring(UrlUtil.FILE_URL_PREFIX.length());
}
}
try {

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.core.io.file;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.regex.ReUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.text.split.SplitUtil;
@ -367,9 +367,9 @@ public class FileNameUtil {
}
// 兼容Spring风格的ClassPath路径去除前缀不区分大小写
String pathToUse = StrUtil.removePrefixIgnoreCase(path, URLUtil.CLASSPATH_URL_PREFIX);
String pathToUse = StrUtil.removePrefixIgnoreCase(path, UrlUtil.CLASSPATH_URL_PREFIX);
// 去除file:前缀
pathToUse = StrUtil.removePrefixIgnoreCase(pathToUse, URLUtil.FILE_URL_PREFIX);
pathToUse = StrUtil.removePrefixIgnoreCase(pathToUse, UrlUtil.FILE_URL_PREFIX);
// 识别home目录形式并转换为绝对路径
if (StrUtil.startWith(pathToUse, '~')) {

View File

@ -24,7 +24,7 @@ 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.net.url.UrlUtil;
import org.dromara.hutool.core.reflect.ClassUtil;
import org.dromara.hutool.core.regex.ReUtil;
import org.dromara.hutool.core.text.CharUtil;
@ -43,6 +43,7 @@ import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
@ -169,30 +170,6 @@ public class FileUtil extends PathUtil {
return loopFiles(file, -1, fileFilter);
}
/**
* 递归遍历目录并处理目录下的文件可以处理目录或文件
* <ul>
* <li>非目录则直接调用{@link Consumer}处理</li>
* <li>目录则递归调用此方法处理</li>
* </ul>
*
* @param file 文件或目录文件直接处理
* @param consumer 文件处理器只会处理文件
* @since 5.5.2
*/
public static void walkFiles(final File file, final Consumer<File> consumer) {
if (file.isDirectory()) {
final File[] subFiles = file.listFiles();
if (ArrayUtil.isNotEmpty(subFiles)) {
for (final File tmp : subFiles) {
walkFiles(tmp, consumer);
}
}
} else {
consumer.accept(file);
}
}
/**
* 递归遍历目录以及子目录中的所有文件<br>
* 如果提供file为文件直接返回过滤结果
@ -230,6 +207,29 @@ public class FileUtil extends PathUtil {
return loopFiles(file, null);
}
/**
* 递归遍历目录并处理目录下的文件可以处理目录或文件
* <ul>
* <li>目录和非目录均调用{@link Predicate}处理</li>
* <li>目录如果{@link Predicate#test(Object)}{@code true}则递归调用此方法处理</li>
* </ul>
* 此方法与{@link #loopFiles(File, FileFilter)}不同的是处理目录判断可减少无效目录的遍历
*
* @param file 文件或目录文件直接处理
* @param predicate 文件处理器只会处理文件
* @since 5.5.2
*/
public static void walkFiles(final File file, final Predicate<File> predicate) {
if (predicate.test(file) && file.isDirectory()) {
final File[] subFiles = file.listFiles();
if (ArrayUtil.isNotEmpty(subFiles)) {
for (final File tmp : subFiles) {
walkFiles(tmp, predicate);
}
}
}
}
/**
* 获得指定目录下所有文件<br>
* 不会扫描子目录<br>
@ -397,7 +397,7 @@ public class FileUtil extends PathUtil {
* @return File
*/
public static File file(final URL url) {
return new File(URLUtil.toURI(url));
return new File(UrlUtil.toURI(url));
}
// endregion
@ -1095,7 +1095,7 @@ public class FileUtil extends PathUtil {
final URL url = ResourceUtil.getResourceUrl(normalPath, baseClass);
if (null != url) {
// 对于jar中文件包含file:前缀需要去掉此类前缀在此做标准化since 3.0.8 解决中文或空格路径被编码的问题
return FileNameUtil.normalize(URLUtil.getDecodedPath(url));
return FileNameUtil.normalize(UrlUtil.getDecodedPath(url));
}
// 如果资源不存在则返回一个拼接的资源绝对路径

View File

@ -16,7 +16,7 @@ import org.dromara.hutool.core.classloader.ClassLoaderUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.io.file.FileNameUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
@ -108,7 +108,7 @@ public class ClassPathResource extends UrlResource {
return this.path;
}
// url在初始化的时候已经断言此处始终不为null
return FileUtil.normalize(URLUtil.getDecodedPath(this.url));
return FileUtil.normalize(UrlUtil.getDecodedPath(this.url));
}
/**

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.core.io.resource;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import javax.tools.FileObject;
import java.io.BufferedReader;
@ -68,7 +68,7 @@ public class FileObjectResource implements Resource {
@Override
public long size() {
return URLUtil.size(getUrl());
return UrlUtil.size(getUrl());
}
@Override

View File

@ -15,7 +15,7 @@ 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.net.url.UrlUtil;
import java.io.File;
import java.io.InputStream;
@ -86,7 +86,7 @@ public class FileResource implements Resource, Serializable {
@Override
public URL getUrl(){
return URLUtil.getURL(this.file);
return UrlUtil.getURL(this.file);
}
@Override

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.core.io.resource;
import org.dromara.hutool.core.compress.ZipUtil;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import java.io.IOException;
import java.net.JarURLConnection;
@ -88,9 +88,9 @@ public class JarResource extends UrlResource {
return jarCon.getJarFile();
} else {
final String urlFile = getUrl().getFile();
int separatorIndex = urlFile.indexOf(URLUtil.WAR_URL_SEPARATOR);
int separatorIndex = urlFile.indexOf(UrlUtil.WAR_URL_SEPARATOR);
if (separatorIndex == -1) {
separatorIndex = urlFile.indexOf(URLUtil.JAR_URL_SEPARATOR);
separatorIndex = urlFile.indexOf(UrlUtil.JAR_URL_SEPARATOR);
}
if (separatorIndex != -1) {
return ZipUtil.ofJar(urlFile.substring(0, separatorIndex));

View File

@ -17,8 +17,9 @@ import org.dromara.hutool.core.compress.ZipUtil;
import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.io.file.FileNameUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.AntPathMatcher;
import org.dromara.hutool.core.text.CharUtil;
import org.dromara.hutool.core.text.StrUtil;
@ -32,6 +33,9 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipException;
/**
* 资源查找器
*/
public class ResourceFinder {
private final ClassLoader classLoader;
@ -54,9 +58,9 @@ public class ResourceFinder {
* @return {@link MultiResource}
*/
public MultiResource find(final String locationPattern) {
// 根目录
// 根目录 "/WEB-INF/*.xml" 返回 "/WEB-INF/"
final String rootDirPath = determineRootDir(locationPattern);
// 子表达式
// 子表达式"/WEB-INF/*.xml" 返回 "*.xml"
final String subPattern = locationPattern.substring(rootDirPath.length());
final MultiResource result = new MultiResource();
@ -98,7 +102,7 @@ public class ResourceFinder {
if (conn instanceof JarURLConnection) {
final JarURLConnection jarCon = (JarURLConnection) conn;
URLUtil.useCachesIfNecessary(jarCon);
UrlUtil.useCachesIfNecessary(jarCon);
jarFile = jarCon.getJarFile();
final JarEntry jarEntry = jarCon.getJarEntry();
rootEntryPath = (jarEntry != null ? jarEntry.getName() : StrUtil.EMPTY);
@ -107,9 +111,9 @@ public class ResourceFinder {
// 去除子路径后重新获取jar文件
final String urlFile = rootDirURL.getFile();
try {
int separatorIndex = urlFile.indexOf(URLUtil.WAR_URL_SEPARATOR);
int separatorIndex = urlFile.indexOf(UrlUtil.WAR_URL_SEPARATOR);
if (separatorIndex == -1) {
separatorIndex = urlFile.indexOf(URLUtil.JAR_URL_SEPARATOR);
separatorIndex = urlFile.indexOf(UrlUtil.JAR_URL_SEPARATOR);
}
if (separatorIndex != -1) {
final String jarFileUrl = urlFile.substring(0, separatorIndex);
@ -136,7 +140,7 @@ public class ResourceFinder {
if (entryPath.startsWith(rootEntryPath)) {
final String relativePath = entryPath.substring(rootEntryPath.length());
if (pathMatcher.match(subPattern, relativePath)) {
result.add(ResourceUtil.getResource(URLUtil.getURL(rootDirURL, relativePath)));
result.add(ResourceUtil.getResource(UrlUtil.getURL(rootDirURL, relativePath)));
}
}
}
@ -159,10 +163,26 @@ public class ResourceFinder {
protected MultiResource findInDir(final FileResource resource, final String subPattern) {
final MultiResource result = new MultiResource();
final File rootDir = resource.getFile();
if(!rootDir.exists() || !rootDir.isDirectory() || !rootDir.canRead()){
// 保证给定文件存在为目录且可读
return result;
}
final String rootPath = rootDir.getAbsolutePath();
final String fullPattern = FileNameUtil.normalize(rootPath + StrUtil.SLASH + subPattern);
FileUtil.walkFiles(rootDir, (file -> {
if (pathMatcher.match(subPattern, file.getName())) {
result.add(new FileResource(file));
final String currentPath = StrUtil.normalize(file.getAbsolutePath());
if(file.isDirectory()){
// 检查目录是否满足表达式开始规则满足则继续向下查找否则跳过
return pathMatcher.matchStart(fullPattern, StrUtil.addSuffixIfNot(currentPath, StrUtil.SLASH));
}
if (pathMatcher.match(fullPattern, currentPath)) {
result.add(new FileResource(file));
return true;
}
return false;
}));
return result;

View File

@ -21,7 +21,7 @@ import org.dromara.hutool.core.net.url.UrlProtocolUtil;
import org.dromara.hutool.core.util.CharsetUtil;
import org.dromara.hutool.core.classloader.ClassLoaderUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.util.ObjUtil;
import java.io.BufferedReader;
@ -239,7 +239,7 @@ public class ResourceUtil {
*/
public static Resource getResource(final String path) {
if (StrUtil.isNotBlank(path)) {
if (path.startsWith(URLUtil.FILE_URL_PREFIX) || FileUtil.isAbsolutePath(path)) {
if (path.startsWith(UrlUtil.FILE_URL_PREFIX) || FileUtil.isAbsolutePath(path)) {
return new FileResource(path);
}
}

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.core.io.resource;
import org.dromara.hutool.core.io.file.FileNameUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.net.url.UrlProtocolUtil;
import org.dromara.hutool.core.util.ObjUtil;
@ -45,7 +45,7 @@ public class UrlResource implements Resource, Serializable {
* @since 5.7.21
*/
public UrlResource(final URI uri) {
this(URLUtil.url(uri), null);
this(UrlUtil.url(uri), null);
}
/**
@ -85,7 +85,7 @@ public class UrlResource implements Resource, Serializable {
@Override
public long size() {
return URLUtil.size(this.url);
return UrlUtil.size(this.url);
}
@Override
@ -93,7 +93,7 @@ public class UrlResource implements Resource, Serializable {
if (null == this.url) {
throw new NoResourceException("Resource URL is null!");
}
return URLUtil.getStream(url);
return UrlUtil.getStream(url);
}
@Override
@ -129,6 +129,6 @@ public class UrlResource implements Resource, Serializable {
* @since 6.0.0
*/
public UrlResource createRelative(final String relativePath) {
return new UrlResource(URLUtil.getURL(getUrl(), relativePath));
return new UrlResource(UrlUtil.getURL(getUrl(), relativePath));
}
}

View File

@ -15,7 +15,7 @@ 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.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.text.CharUtil;
@ -77,7 +77,7 @@ public class WatchMonitor extends WatchServer {
* @return 监听对象
*/
public static WatchMonitor of(final URL url, final int maxDepth, final WatchEvent.Kind<?>... events) {
return of(URLUtil.toURI(url), maxDepth, events);
return of(UrlUtil.toURI(url), maxDepth, events);
}
/**

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.core.io.watch;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import java.io.File;
import java.io.IOException;
@ -54,7 +54,7 @@ public class WatchUtil {
* @return 监听对象
*/
public static WatchMonitor of(final URL url, final int maxDepth, final WatchEvent.Kind<?>... events) {
return of(URLUtil.toURI(url), maxDepth, events);
return of(UrlUtil.toURI(url), maxDepth, events);
}
/**
@ -170,7 +170,7 @@ public class WatchUtil {
* @return {@link WatchMonitor}
*/
public static WatchMonitor ofAll(final URL url, final int maxDepth, final Watcher watcher) {
return ofAll(URLUtil.toURI(url), maxDepth, watcher);
return ofAll(UrlUtil.toURI(url), maxDepth, watcher);
}
/**
@ -290,7 +290,7 @@ public class WatchUtil {
* @since 4.5.2
*/
public static WatchMonitor createModify(final URL url, final int maxDepth, final Watcher watcher) {
return createModify(URLUtil.toURI(url), maxDepth, watcher);
return createModify(UrlUtil.toURI(url), maxDepth, watcher);
}
/**

View File

@ -160,7 +160,7 @@ public final class UrlBuilder implements Builder<String> {
*/
public static UrlBuilder of(final String url, final Charset charset) {
Assert.notBlank(url, "Url must be not blank!");
return of(URLUtil.url(StrUtil.trim(url)), charset);
return of(UrlUtil.url(StrUtil.trim(url)), charset);
}
/**

View File

@ -31,7 +31,7 @@ import java.nio.charset.Charset;
*
* @author looly
*/
public class URLDecoder implements Serializable {
public class UrlDecoder implements Serializable {
private static final long serialVersionUID = 1L;
private static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;

View File

@ -24,7 +24,7 @@ import java.nio.charset.Charset;
* @author looly
* @since 6.0.0
*/
public class URLEncoder {
public class UrlEncoder {
private static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;

View File

@ -129,7 +129,7 @@ public class UrlPath {
if (StrUtil.isNotEmpty(path)) {
final List<String> split = SplitUtil.split(path, StrUtil.SLASH);
for (final String seg : split) {
addInternal(URLDecoder.decodeForPath(seg, charset), false);
addInternal(UrlDecoder.decodeForPath(seg, charset), false);
}
}
}

View File

@ -17,6 +17,13 @@ import org.dromara.hutool.core.lang.Assert;
import java.net.URL;
/**
* URL协议相关工具类<br>
* 用于判断URL的协议类型如jar或file等
*
* @author looly
* @since 6.0.0
*/
public class UrlProtocolUtil {
/**
* URL 协议表示文件: "file"

View File

@ -427,11 +427,11 @@ public class UrlQuery {
private void addParam(final String key, final String value, final Charset charset) {
final boolean isFormUrlEncoded = EncodeMode.FORM_URL_ENCODED == this.encodeMode;
if (null != key) {
final String actualKey = URLDecoder.decode(key, charset, isFormUrlEncoded);
this.query.put(actualKey, StrUtil.emptyIfNull(URLDecoder.decode(value, charset, isFormUrlEncoded)));
final String actualKey = UrlDecoder.decode(key, charset, isFormUrlEncoded);
this.query.put(actualKey, StrUtil.emptyIfNull(UrlDecoder.decode(value, charset, isFormUrlEncoded)));
} else if (null != value) {
// name为空value作为namevalue赋值null
this.query.put(URLDecoder.decode(value, charset, isFormUrlEncoded), null);
this.query.put(UrlDecoder.decode(value, charset, isFormUrlEncoded), null);
}
}

View File

@ -164,13 +164,13 @@ public class UrlQueryUtil {
// 结尾处理
if (null != name) {
builder.append(URLEncoder.encodeQuery(name, charset)).append('=');
builder.append(UrlEncoder.encodeQuery(name, charset)).append('=');
}
if (pos != i) {
if (null == name && pos > 0) {
builder.append('=');
}
builder.append(URLEncoder.encodeQuery(queryPart.substring(pos, i), charset));
builder.append(UrlEncoder.encodeQuery(queryPart.substring(pos, i), charset));
}
// &结尾则去除之

View File

@ -44,7 +44,7 @@ import java.util.Map;
*
* @author looly
*/
public class URLUtil {
public class UrlUtil {
// region const
/**
@ -171,7 +171,7 @@ public class URLUtil {
public static URL toUrlForHttp(String urlStr, final URLStreamHandler handler) {
Assert.notBlank(urlStr, "Url is blank !");
// 编码空白符防止空格引起的请求异常
urlStr = URLEncoder.encodeBlank(urlStr);
urlStr = UrlEncoder.encodeBlank(urlStr);
try {
return new URL(null, urlStr, handler);
} catch (final MalformedURLException e) {

View File

@ -20,7 +20,7 @@ import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.file.FileNameUtil;
import org.dromara.hutool.core.io.resource.JarResource;
import org.dromara.hutool.core.io.resource.ResourceUtil;
import org.dromara.hutool.core.net.url.URLDecoder;
import org.dromara.hutool.core.net.url.UrlDecoder;
import org.dromara.hutool.core.text.CharUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.CharsetUtil;
@ -264,7 +264,7 @@ public class ClassScanner implements Serializable {
for (final URL url : ResourceUtil.getResourceUrlIter(this.packagePath, this.classLoader)) {
switch (url.getProtocol()) {
case "file":
scanFile(new File(URLDecoder.decode(url.getFile(), this.charset)), null);
scanFile(new File(UrlDecoder.decode(url.getFile(), this.charset)), null);
break;
case "jar":
scanJar(new JarResource(url).getJarFile());
@ -326,7 +326,7 @@ public class ClassScanner implements Serializable {
final String[] javaClassPaths = SystemUtil.getJavaClassPaths();
for (String classPath : javaClassPaths) {
// bug修复由于路径中空格和中文导致的Jar找不到
classPath = URLDecoder.decode(classPath, CharsetUtil.defaultCharset());
classPath = UrlDecoder.decode(classPath, CharsetUtil.defaultCharset());
scanFile(new File(classPath), null);
}

View File

@ -19,8 +19,8 @@ import org.dromara.hutool.core.convert.BasicType;
import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.io.resource.ResourceUtil;
import org.dromara.hutool.core.net.url.URLDecoder;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlDecoder;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.CharUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.text.split.SplitUtil;
@ -311,7 +311,7 @@ public class ClassUtil {
String path;
while (resources.hasMoreElements()) {
path = resources.nextElement().getPath();
paths.add(isDecode ? URLDecoder.decode(path, CharsetUtil.defaultCharset()) : path);
paths.add(isDecode ? UrlDecoder.decode(path, CharsetUtil.defaultCharset()) : path);
}
return paths;
}
@ -335,7 +335,7 @@ public class ClassUtil {
*/
public static String getClassPath(final boolean isEncoded) {
final URL classPathUrl = ResourceUtil.getResourceUrl(StrUtil.EMPTY);
final String url = isEncoded ? classPathUrl.getPath() : URLUtil.getDecodedPath(classPathUrl);
final String url = isEncoded ? classPathUrl.getPath() : UrlUtil.getDecodedPath(classPathUrl);
return FileUtil.normalize(url);
}

View File

@ -12,11 +12,8 @@
package org.dromara.hutool.core.net;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.net.url.URLDecoder;
import org.dromara.hutool.core.net.url.URLEncoder;
import org.dromara.hutool.core.net.url.UrlQuery;
import org.dromara.hutool.core.util.CharsetUtil;
import org.dromara.hutool.core.net.url.UrlDecoder;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -25,26 +22,26 @@ public class URLEncoderTest {
@Test
void encodeTest() {
final String body = "366466 - 副本.jpg";
final String encode = URLEncoder.encodeAll(body);
final String encode = UrlEncoder.encodeAll(body);
Assertions.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode);
Assertions.assertEquals(body, URLDecoder.decode(encode));
Assertions.assertEquals(body, UrlDecoder.decode(encode));
final String encode2 = URLEncoder.encodeQuery(body);
final String encode2 = UrlEncoder.encodeQuery(body);
Assertions.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode2);
}
@Test
void encodeQueryPlusTest() {
final String body = "+";
final String encode2 = URLEncoder.encodeQuery(body);
final String encode2 = UrlEncoder.encodeQuery(body);
Assertions.assertEquals("+", encode2);
}
@Test
void encodeEmojiTest() {
final String emoji = "🐶😊😂🤣";
final String encode = URLEncoder.encodeAll(emoji);
final String encode = UrlEncoder.encodeAll(emoji);
Assertions.assertEquals("%F0%9F%90%B6%F0%9F%98%8A%F0%9F%98%82%F0%9F%A4%A3", encode);
Assertions.assertEquals(emoji, URLDecoder.decode(encode));
Assertions.assertEquals(emoji, UrlDecoder.decode(encode));
}
}

View File

@ -12,7 +12,7 @@
package org.dromara.hutool.core.net;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -32,66 +32,66 @@ public class URLUtilTest {
public void normalizeTest() {
// issue#I25MZL多个/被允许
String url = "http://www.hutool.cn//aaa/bbb";
String normalize = URLUtil.normalize(url);
String normalize = UrlUtil.normalize(url);
Assertions.assertEquals("http://www.hutool.cn//aaa/bbb", normalize);
url = "www.hutool.cn//aaa/bbb";
normalize = URLUtil.normalize(url);
normalize = UrlUtil.normalize(url);
Assertions.assertEquals("http://www.hutool.cn//aaa/bbb", normalize);
}
@Test
public void normalizeTest2() {
String url = "http://www.hutool.cn//aaa/\\bbb?a=1&b=2";
String normalize = URLUtil.normalize(url);
String normalize = UrlUtil.normalize(url);
Assertions.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize);
url = "www.hutool.cn//aaa/bbb?a=1&b=2";
normalize = URLUtil.normalize(url);
normalize = UrlUtil.normalize(url);
Assertions.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize);
}
@Test
public void normalizeTest3() {
String url = "http://www.hutool.cn//aaa/\\bbb?a=1&b=2";
String normalize = URLUtil.normalize(url, true);
String normalize = UrlUtil.normalize(url, true);
Assertions.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize);
url = "www.hutool.cn//aaa/bbb?a=1&b=2";
normalize = URLUtil.normalize(url, true);
normalize = UrlUtil.normalize(url, true);
Assertions.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize);
url = "\\/www.hutool.cn//aaa/bbb?a=1&b=2";
normalize = URLUtil.normalize(url, true);
normalize = UrlUtil.normalize(url, true);
Assertions.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize);
}
@Test
public void normalizeIpv6Test() {
final String url = "http://[fe80::8f8:2022:a603:d180]:9439";
final String normalize = URLUtil.normalize("http://[fe80::8f8:2022:a603:d180]:9439", true);
final String normalize = UrlUtil.normalize("http://[fe80::8f8:2022:a603:d180]:9439", true);
Assertions.assertEquals(url, normalize);
}
@Test
public void formatTest() {
final String url = "//www.hutool.cn//aaa/\\bbb?a=1&b=2";
final String normalize = URLUtil.normalize(url);
final String normalize = UrlUtil.normalize(url);
Assertions.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize);
}
@Test
public void getHostTest() throws MalformedURLException {
final String url = "https://www.hutool.cn//aaa/\\bbb?a=1&b=2";
final String normalize = URLUtil.normalize(url);
final URI host = URLUtil.getHost(new URL(normalize));
final String normalize = UrlUtil.normalize(url);
final URI host = UrlUtil.getHost(new URL(normalize));
Assertions.assertEquals("https://www.hutool.cn", host.toString());
}
@Test
public void getPathTest(){
final String url = " http://www.aaa.bbb/search?scope=ccc&q=ddd";
final String path = URLUtil.getPath(url);
final String path = UrlUtil.getPath(url);
Assertions.assertEquals("/search", path);
}
}

View File

@ -12,8 +12,8 @@
package org.dromara.hutool.core.net;
import org.dromara.hutool.core.net.url.URLDecoder;
import org.dromara.hutool.core.net.url.URLEncoder;
import org.dromara.hutool.core.net.url.UrlDecoder;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.dromara.hutool.core.util.CharsetUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -25,12 +25,12 @@ class UrlDecoderTest {
@Test
void decodeForPathTest() {
Assertions.assertEquals("+", URLDecoder.decodeForPath("+", CharsetUtil.UTF_8));
Assertions.assertEquals("+", UrlDecoder.decodeForPath("+", CharsetUtil.UTF_8));
}
@Test
public void decodePlusTest() {
final String decode = URLDecoder.decode("+", CharsetUtil.UTF_8);
final String decode = UrlDecoder.decode("+", CharsetUtil.UTF_8);
Assertions.assertEquals(" ", decode);
}
@ -41,36 +41,36 @@ class UrlDecoderTest {
final String s = "测试";
final String expectedDecode = "%FE%FF%6D%4B%8B%D5";
final String s1 = URLEncoder.encodeAll(s, StandardCharsets.UTF_16);
final String s1 = UrlEncoder.encodeAll(s, StandardCharsets.UTF_16);
Assertions.assertEquals(expectedDecode, s1);
final String s2 = java.net.URLEncoder.encode(s, "UTF-16");
Assertions.assertEquals(expectedDecode, s2);
final String decode = URLDecoder.decode(s1, StandardCharsets.UTF_16);
final String decode = UrlDecoder.decode(s1, StandardCharsets.UTF_16);
Assertions.assertEquals(s, decode);
// 测试编码字符串和非编码字符串混合
final String mixDecoded = expectedDecode + "你好";
final String decode2 = URLDecoder.decode(mixDecoded, StandardCharsets.UTF_16);
final String decode2 = UrlDecoder.decode(mixDecoded, StandardCharsets.UTF_16);
Assertions.assertEquals("测试你好", decode2);
Assertions.assertEquals(
java.net.URLDecoder.decode(mixDecoded, "UTF-16"),
URLDecoder.decode(mixDecoded, StandardCharsets.UTF_16)
UrlDecoder.decode(mixDecoded, StandardCharsets.UTF_16)
);
}
@Test
void decodeCharSetIsNullToStrTest() {
final String hello = "你好";
String decode = URLDecoder.decode(hello, null, true);
String decode = UrlDecoder.decode(hello, null, true);
Assertions.assertEquals(hello, decode);
}
@Test
void decodeStrIsEmptyToStrTest() {
final String strEmpty = "";
String decode = URLDecoder.decode(strEmpty, StandardCharsets.UTF_8, true);
String decode = UrlDecoder.decode(strEmpty, StandardCharsets.UTF_8, true);
Assertions.assertEquals(strEmpty, decode);
}
@ -78,19 +78,19 @@ class UrlDecoderTest {
void decodeStrWithUTF8ToStrTest() {
final String exceptedDecode = "你好";
final String encode = "%E4%BD%A0%E5%A5%BD";
String s1 = URLDecoder.decode(encode);
String s1 = UrlDecoder.decode(encode);
Assertions.assertEquals(exceptedDecode, s1);
String s2 = URLDecoder.decode(encode, StandardCharsets.UTF_8);
String s2 = UrlDecoder.decode(encode, StandardCharsets.UTF_8);
Assertions.assertEquals(exceptedDecode, s2);
String s3 = URLDecoder.decode(encode, true);
String s3 = UrlDecoder.decode(encode, true);
Assertions.assertEquals(exceptedDecode, s3);
String s4 = URLDecoder.decode(encode + "+", false);
String s4 = UrlDecoder.decode(encode + "+", false);
Assertions.assertEquals(exceptedDecode + "+", s4);
String s5 = URLDecoder.decode(encode, StandardCharsets.UTF_8, false);
String s5 = UrlDecoder.decode(encode, StandardCharsets.UTF_8, false);
Assertions.assertEquals(exceptedDecode, s5);
}
@ -98,10 +98,10 @@ class UrlDecoderTest {
void decodeStrWithUTF8ToByteTest(){
final String exceptedDecode = "你好";
final String encode = "%E4%BD%A0%E5%A5%BD";
byte[] decode = URLDecoder.decode(encode.getBytes(StandardCharsets.UTF_8));
byte[] decode = UrlDecoder.decode(encode.getBytes(StandardCharsets.UTF_8));
Assertions.assertEquals(exceptedDecode, new String(decode,StandardCharsets.UTF_8));
byte[] decode1 = URLDecoder.decode((encode + "+").getBytes(StandardCharsets.UTF_8));
byte[] decode1 = UrlDecoder.decode((encode + "+").getBytes(StandardCharsets.UTF_8));
Assertions.assertEquals(exceptedDecode+" ",new String(decode1,StandardCharsets.UTF_8));
}
}

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.core.net;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.net.url.UrlBuilder;
import org.dromara.hutool.core.net.url.UrlQuery;
import org.dromara.hutool.core.util.CharsetUtil;
@ -58,7 +58,7 @@ public class UrlQueryTest {
public void parseTest3() {
// issue#1688@Github
final String u = "https://www.baidu.com/proxy";
final UrlQuery query = UrlQuery.of(URLUtil.url(u).getQuery(), Charset.defaultCharset());
final UrlQuery query = UrlQuery.of(UrlUtil.url(u).getQuery(), Charset.defaultCharset());
Assertions.assertTrue(MapUtil.isEmpty(query.getQueryMap()));
}
@ -75,13 +75,13 @@ public class UrlQueryTest {
Map<String, String> map = new LinkedHashMap<>();
map.put("username", "SSM");
map.put("password", "123456");
String query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
String query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("username=SSM&password=123456", query);
map = new TreeMap<>();
map.put("username", "SSM");
map.put("password", "123456");
query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("password=123456&username=SSM", query);
}
@ -90,19 +90,19 @@ public class UrlQueryTest {
Map<String, String> map = new LinkedHashMap<>();
map.put(null, "SSM");
map.put("password", "123456");
String query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
String query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("password=123456", query);
map = new TreeMap<>();
map.put("username", "SSM");
map.put("password", "");
query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("password=&username=SSM", query);
map = new TreeMap<>();
map.put("username", "SSM");
map.put("password", null);
query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("password&username=SSM", query);
}
@ -111,13 +111,13 @@ public class UrlQueryTest {
Map<String, String> map = new LinkedHashMap<>();
map.put("key1&", "SSM");
map.put("key2", "123456&");
String query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
String query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("key1%26=SSM&key2=123456%26", query);
map = new TreeMap<>();
map.put("username=", "SSM");
map.put("password", "=");
query = URLUtil.buildQuery(map, StandardCharsets.UTF_8);
query = UrlUtil.buildQuery(map, StandardCharsets.UTF_8);
Assertions.assertEquals("password==&username%3D=SSM", query);
}

View File

@ -27,7 +27,7 @@ public class IssueI6ZF6KTest {
final Map<String, Object> form = MapBuilder.<String, Object>of()
.put("condition", json)
.build();
final String requestBody = URLUtil.buildQuery(form, CharsetUtil.UTF_8);
final String requestBody = UrlUtil.buildQuery(form, CharsetUtil.UTF_8);
Console.log(requestBody);
}
}

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.http.client.cookie;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.http.client.engine.jdk.JdkHttpConnection;
import java.io.IOException;
@ -137,6 +137,6 @@ public class GlobalCookieManager {
* @return URI
*/
private static URI getURI(final JdkHttpConnection conn){
return URLUtil.toURI(conn.getUrl());
return UrlUtil.toURI(conn.getUrl());
}
}

View File

@ -148,7 +148,7 @@ public class JdkClientEngine implements ClientEngine {
* @param isAsync 最终请求是否异步
* @return {@link JdkHttpResponse}无转发返回 {@code null}
*/
private JdkHttpResponse sendRedirectIfPossible(JdkHttpConnection conn, final Request message, final boolean isAsync) {
private JdkHttpResponse sendRedirectIfPossible(final JdkHttpConnection conn, final Request message, final boolean isAsync) {
// 手动实现重定向
if (message.maxRedirectCount() > 0) {
final int code;

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.http.client.engine.jdk;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.reflect.FieldUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.http.HttpException;
@ -52,7 +52,7 @@ public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection>, Cl
* @return HttpConnection
*/
public static JdkHttpConnection of(final String urlStr, final Proxy proxy) {
return of(URLUtil.toUrlForHttp(urlStr), proxy);
return of(UrlUtil.toUrlForHttp(urlStr), proxy);
}
/**

View File

@ -15,7 +15,7 @@ package org.dromara.hutool.http.server;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.net.url.URLEncoder;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ByteUtil;
import org.dromara.hutool.core.util.ObjUtil;
@ -435,7 +435,7 @@ public class HttpServerResponse extends HttpServerBase {
if (!contentType.startsWith("text/")) {
// 非文本类型数据直接走下载
setHeader(HeaderName.CONTENT_DISPOSITION, StrUtil.format("attachment;filename={}", URLEncoder.encodeAll(fileName, charset)));
setHeader(HeaderName.CONTENT_DISPOSITION, StrUtil.format("attachment;filename={}", UrlEncoder.encodeAll(fileName, charset)));
}
return write(in, length, contentType);
}

View File

@ -24,7 +24,7 @@ import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.map.CaseInsensitiveMap;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.net.NetUtil;
import org.dromara.hutool.core.net.url.URLEncoder;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.dromara.hutool.core.net.multipart.MultipartFormData;
import org.dromara.hutool.core.net.multipart.UploadSetting;
import org.dromara.hutool.core.reflect.ConstructorUtil;
@ -607,7 +607,7 @@ public class JakartaServletUtil {
*/
public static void write(final HttpServletResponse response, final InputStream in, final String contentType, final String fileName) {
final String charset = ObjUtil.defaultIfNull(response.getCharacterEncoding(), CharsetUtil.NAME_UTF_8);
final String encodeText = URLEncoder.encodeAll(fileName, CharsetUtil.charset(charset));
final String encodeText = UrlEncoder.encodeAll(fileName, CharsetUtil.charset(charset));
response.setHeader("Content-Disposition",
StrUtil.format("attachment;filename=\"{}\";filename*={}''{}", encodeText, charset, encodeText));
response.setContentType(contentType);

View File

@ -26,7 +26,7 @@ import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.net.NetUtil;
import org.dromara.hutool.core.net.multipart.MultipartFormData;
import org.dromara.hutool.core.net.multipart.UploadSetting;
import org.dromara.hutool.core.net.url.URLEncoder;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.dromara.hutool.core.reflect.ConstructorUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.array.ArrayUtil;
@ -618,7 +618,7 @@ public class ServletUtil {
*/
public static void write(final HttpServletResponse response, final InputStream in, final String contentType, final String fileName) {
final String charset = ObjUtil.defaultIfNull(response.getCharacterEncoding(), CharsetUtil.NAME_UTF_8);
final String encodeText = URLEncoder.encodeAll(fileName, CharsetUtil.charset(charset));
final String encodeText = UrlEncoder.encodeAll(fileName, CharsetUtil.charset(charset));
response.setHeader("Content-Disposition",
StrUtil.format("attachment;filename=\"{}\";filename*={}''{}", encodeText, charset, encodeText));
response.setContentType(contentType);

View File

@ -16,7 +16,7 @@ import org.apache.poi.ss.usermodel.*;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.net.url.URLEncoder;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.CharsetUtil;
import org.dromara.hutool.poi.excel.cell.CellLocation;
@ -556,7 +556,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
fileName = IdUtil.fastSimpleUUID();
}
fileName = StrUtil.addSuffixIfNot(URLEncoder.encodeAll(fileName, charset), isXlsx() ? ".xlsx" : ".xls");
fileName = StrUtil.addSuffixIfNot(UrlEncoder.encodeAll(fileName, charset), isXlsx() ? ".xlsx" : ".xls");
return StrUtil.format("attachment; filename=\"{}\"", fileName);
}

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.setting;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.util.CharsetUtil;
@ -83,7 +83,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
pathBaseClassLoader = StrUtil.EMPTY;
}
final URL url = URLUtil.getURL(pathBaseClassLoader);
final URL url = UrlUtil.getURL(pathBaseClassLoader);
if (url == null) {
throw new RuntimeException(StrUtil.format("Can not find GroupSet file: [{}]", pathBaseClassLoader));
}
@ -100,7 +100,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
if (configFile == null) {
throw new RuntimeException("Null GroupSet file!");
}
final URL url = URLUtil.getURL(configFile);
final URL url = UrlUtil.getURL(configFile);
this.init(url, charset);
}
@ -112,7 +112,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
* @param charset 字符集
*/
public GroupedSet(final String path, final Class<?> clazz, final Charset charset) {
final URL url = URLUtil.getURL(path, clazz);
final URL url = UrlUtil.getURL(path, clazz);
if (url == null) {
throw new RuntimeException(StrUtil.format("Can not find GroupSet file: [{}]", path));
}

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.swing;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import java.awt.Desktop;
import java.io.File;
@ -44,7 +44,7 @@ public class DesktopUtil {
* @param url URL地址
*/
public static void browse(final String url) {
browse(URLUtil.toURI(url));
browse(UrlUtil.toURI(url));
}
/**
@ -112,7 +112,7 @@ public class DesktopUtil {
public static void mail(final String mailAddress) {
final Desktop dsktop = getDsktop();
try {
dsktop.mail(URLUtil.toURI(mailAddress));
dsktop.mail(UrlUtil.toURI(mailAddress));
} catch (final IOException e) {
throw new IORuntimeException(e);
}

View File

@ -16,7 +16,7 @@ import org.dromara.hutool.core.codec.binary.Base64;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.swing.captcha.generator.CodeGenerator;
import org.dromara.hutool.swing.captcha.generator.RandomGenerator;
import org.dromara.hutool.swing.img.ImgUtil;
@ -214,7 +214,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @since 5.3.11
*/
public String getImageBase64Data(){
return URLUtil.getDataUriBase64("image/png", getImageBase64());
return UrlUtil.getDataUriBase64("image/png", getImageBase64());
}
/**

View File

@ -21,7 +21,7 @@ import org.dromara.hutool.core.io.resource.Resource;
import org.dromara.hutool.core.io.stream.FastByteArrayOutputStream;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.math.NumberUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.dromara.hutool.core.text.StrUtil;
import javax.imageio.ImageIO;
@ -1349,7 +1349,7 @@ public class ImgUtil {
* @since 5.3.6
*/
public static String toBase64DataUri(final Image image, final String imageType) {
return URLUtil.getDataUri(
return UrlUtil.getDataUri(
"image/" + imageType, "base64",
toBase64(image, imageType));
}

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.swing.img;
import org.dromara.hutool.core.io.file.FileTypeUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.net.url.URLUtil;
import org.dromara.hutool.core.net.url.UrlUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -105,7 +105,7 @@ public class ImgTest {
final File file = FileUtil.file(downloadFile);
final File fileScale = FileUtil.file(downloadFile + ".scale." + FileTypeUtil.getType(file));
final Image img = ImgUtil.getImage(URLUtil.getURL(file));
final Image img = ImgUtil.getImage(UrlUtil.getURL(file));
ImgUtil.scale(img, fileScale, 0.8f);
}