mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
0db70ea1d7
commit
73152c5361
@ -18,6 +18,10 @@ import org.junit.jupiter.api.Assertions;
|
|||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文本相似度计算工具类单元测试
|
* 文本相似度计算工具类单元测试
|
||||||
*
|
*
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|||||||
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
|
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
|
||||||
import org.springframework.context.*;
|
import org.springframework.context.*;
|
||||||
import org.springframework.core.ResolvableType;
|
import org.springframework.core.ResolvableType;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -167,10 +168,45 @@ public class SpringUtil implements ApplicationContextInitializer<ConfigurableApp
|
|||||||
* @since 5.3.3
|
* @since 5.3.3
|
||||||
*/
|
*/
|
||||||
public static String getProperty(final String key) {
|
public static String getProperty(final String key) {
|
||||||
if (null == applicationContext) {
|
final ConfigurableEnvironment environment = getEnvironment();
|
||||||
return null;
|
return null == environment ? null : environment.getProperty(key);
|
||||||
}
|
}
|
||||||
return applicationContext.getEnvironment().getProperty(key);
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件配置项的值
|
||||||
|
*
|
||||||
|
* @param key 配置项key
|
||||||
|
* @param defaultValue 默认值
|
||||||
|
* @return 属性值
|
||||||
|
* @since 5.8.24
|
||||||
|
*/
|
||||||
|
public static String getProperty(final String key, final String defaultValue) {
|
||||||
|
final ConfigurableEnvironment environment = getEnvironment();
|
||||||
|
return null == environment ? null : environment.getProperty(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件配置项的值
|
||||||
|
*
|
||||||
|
* @param <T> 属性值类型
|
||||||
|
* @param key 配置项key
|
||||||
|
* @param targetType 配置项类型
|
||||||
|
* @param defaultValue 默认值
|
||||||
|
* @return 属性值
|
||||||
|
* @since 5.8.24
|
||||||
|
*/
|
||||||
|
public static <T> T getProperty(final String key, final Class<T> targetType, final T defaultValue) {
|
||||||
|
final ConfigurableEnvironment environment = getEnvironment();
|
||||||
|
return null == environment ? null : environment.getProperty(key, targetType, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取环境属性
|
||||||
|
*
|
||||||
|
* @return {@link ConfigurableEnvironment}
|
||||||
|
*/
|
||||||
|
public static ConfigurableEnvironment getEnvironment() {
|
||||||
|
return null == applicationContext ? null : applicationContext.getEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -501,28 +501,22 @@ public class ImgUtil {
|
|||||||
* 图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
|
* 图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
|
||||||
*
|
*
|
||||||
* @param srcImageFile 源图像文件
|
* @param srcImageFile 源图像文件
|
||||||
* @param destImageFile 目标图像文件
|
* @param targetImageFile 目标图像文件
|
||||||
*/
|
*/
|
||||||
public static void convert(final File srcImageFile, final File destImageFile) {
|
public static void convert(final File srcImageFile, final File targetImageFile) {
|
||||||
Assert.notNull(srcImageFile);
|
Assert.notNull(srcImageFile);
|
||||||
Assert.notNull(destImageFile);
|
Assert.notNull(targetImageFile);
|
||||||
Assert.isFalse(srcImageFile.equals(destImageFile), "Src file is equals to dest file!");
|
Assert.isFalse(srcImageFile.equals(targetImageFile), "Src file is equals to dest file!");
|
||||||
|
|
||||||
// 通过扩展名检查图片类型,相同类型直接复制
|
// 通过扩展名检查图片类型,相同类型直接复制
|
||||||
final String srcExtName = FileNameUtil.extName(srcImageFile);
|
final String srcExtName = FileNameUtil.extName(srcImageFile);
|
||||||
final String destExtName = FileNameUtil.extName(destImageFile);
|
final String destExtName = FileNameUtil.extName(targetImageFile);
|
||||||
if (StrUtil.equalsIgnoreCase(srcExtName, destExtName)) {
|
if (StrUtil.equalsIgnoreCase(srcExtName, destExtName)) {
|
||||||
// 扩展名相同直接复制文件
|
// 扩展名相同直接复制文件
|
||||||
FileUtil.copy(srcImageFile, destImageFile, true);
|
FileUtil.copy(srcImageFile, targetImageFile, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageOutputStream imageOutputStream = null;
|
Img.from(srcImageFile).write(targetImageFile);
|
||||||
try {
|
|
||||||
imageOutputStream = getImageOutputStream(destImageFile);
|
|
||||||
convert(read(srcImageFile), destExtName, imageOutputStream, StrUtil.equalsIgnoreCase(IMAGE_TYPE_PNG, srcExtName));
|
|
||||||
} finally {
|
|
||||||
IoUtil.closeQuietly(imageOutputStream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -531,11 +525,11 @@ public class ImgUtil {
|
|||||||
*
|
*
|
||||||
* @param srcStream 源图像流
|
* @param srcStream 源图像流
|
||||||
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
||||||
* @param destStream 目标图像输出流
|
* @param targetStream 目标图像输出流
|
||||||
* @since 3.0.9
|
* @since 3.0.9
|
||||||
*/
|
*/
|
||||||
public static void convert(final InputStream srcStream, final String formatName, final OutputStream destStream) {
|
public static void convert(final InputStream srcStream, final String formatName, final OutputStream targetStream) {
|
||||||
write(read(srcStream), formatName, getImageOutputStream(destStream));
|
write(read(srcStream), formatName, getImageOutputStream(targetStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -544,17 +538,11 @@ public class ImgUtil {
|
|||||||
*
|
*
|
||||||
* @param srcImage 源图像流
|
* @param srcImage 源图像流
|
||||||
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
||||||
* @param destImageStream 目标图像输出流
|
* @param targetImageStream 目标图像输出流
|
||||||
* @param isSrcPng 源图片是否为PNG格式
|
|
||||||
* @since 4.1.14
|
* @since 4.1.14
|
||||||
*/
|
*/
|
||||||
public static void convert(final Image srcImage, final String formatName, final ImageOutputStream destImageStream, final boolean isSrcPng) {
|
public static void convert(final Image srcImage, final String formatName, final ImageOutputStream targetImageStream) {
|
||||||
final BufferedImage src = toBufferedImage(srcImage, isSrcPng ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
|
Img.from(srcImage).setTargetImageType(formatName).write(targetImageStream);
|
||||||
try {
|
|
||||||
ImageIO.write(src, formatName, destImageStream);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new IORuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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:
|
||||||
|
* https://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.swing.img;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.io.file.FileUtil;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class IssueI8L8UATest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void convertTest() {
|
||||||
|
ImgUtil.convert(
|
||||||
|
FileUtil.file("d:/test/1.png"),
|
||||||
|
FileUtil.file("d:/test/1.jpg"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user