mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
e71cc5bc32
commit
bf0466ef76
@ -21,6 +21,8 @@
|
|||||||
* 【http 】 HttpServerRequest增加getParam方法
|
* 【http 】 HttpServerRequest增加getParam方法
|
||||||
* 【http 】 RootAction增加可选name参数,返回指定文件名称
|
* 【http 】 RootAction增加可选name参数,返回指定文件名称
|
||||||
* 【db 】 支持人大金仓8的驱动识别
|
* 【db 】 支持人大金仓8的驱动识别
|
||||||
|
* 【db 】 ThreadUtil增加createScheduledExecutor和schedule方法(issue#I2NUTC@Gitee)
|
||||||
|
* 【core 】 ImgUtil增加getImage方法(issue#I2DU1Z@Gitee)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复FileUtil.move以及PathUtil.copy等无法自动创建父目录的问题(issue#I2CKTI@Gitee)
|
* 【core 】 修复FileUtil.move以及PathUtil.copy等无法自动创建父目录的问题(issue#I2CKTI@Gitee)
|
||||||
|
@ -29,6 +29,7 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.font.FontRenderContext;
|
import java.awt.font.FontRenderContext;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
@ -183,7 +184,7 @@ public class ImgUtil {
|
|||||||
* @param destImageFile 缩放后的图像地址
|
* @param destImageFile 缩放后的图像地址
|
||||||
* @param width 缩放后的宽度
|
* @param width 缩放后的宽度
|
||||||
* @param height 缩放后的高度
|
* @param height 缩放后的高度
|
||||||
* @param fixedColor 补充的颜色,不补充为<code>null</code>
|
* @param fixedColor 补充的颜色,不补充为{@code null}
|
||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public static void scale(File srcImageFile, File destImageFile, int width, int height, Color fixedColor) throws IORuntimeException {
|
public static void scale(File srcImageFile, File destImageFile, int width, int height, Color fixedColor) throws IORuntimeException {
|
||||||
@ -201,7 +202,7 @@ public class ImgUtil {
|
|||||||
* @param destStream 缩放后的图像目标流
|
* @param destStream 缩放后的图像目标流
|
||||||
* @param width 缩放后的宽度
|
* @param width 缩放后的宽度
|
||||||
* @param height 缩放后的高度
|
* @param height 缩放后的高度
|
||||||
* @param fixedColor 比例不对时补充的颜色,不补充为<code>null</code>
|
* @param fixedColor 比例不对时补充的颜色,不补充为{@code null}
|
||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public static void scale(InputStream srcStream, OutputStream destStream, int width, int height, Color fixedColor) throws IORuntimeException {
|
public static void scale(InputStream srcStream, OutputStream destStream, int width, int height, Color fixedColor) throws IORuntimeException {
|
||||||
@ -216,7 +217,7 @@ public class ImgUtil {
|
|||||||
* @param destStream 缩放后的图像目标流
|
* @param destStream 缩放后的图像目标流
|
||||||
* @param width 缩放后的宽度
|
* @param width 缩放后的宽度
|
||||||
* @param height 缩放后的高度
|
* @param height 缩放后的高度
|
||||||
* @param fixedColor 比例不对时补充的颜色,不补充为<code>null</code>
|
* @param fixedColor 比例不对时补充的颜色,不补充为{@code null}
|
||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public static void scale(ImageInputStream srcStream, ImageOutputStream destStream, int width, int height, Color fixedColor) throws IORuntimeException {
|
public static void scale(ImageInputStream srcStream, ImageOutputStream destStream, int width, int height, Color fixedColor) throws IORuntimeException {
|
||||||
@ -231,7 +232,7 @@ public class ImgUtil {
|
|||||||
* @param destImageStream 缩放后的图像目标流
|
* @param destImageStream 缩放后的图像目标流
|
||||||
* @param width 缩放后的宽度
|
* @param width 缩放后的宽度
|
||||||
* @param height 缩放后的高度
|
* @param height 缩放后的高度
|
||||||
* @param fixedColor 比例不对时补充的颜色,不补充为<code>null</code>
|
* @param fixedColor 比例不对时补充的颜色,不补充为{@code null}
|
||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public static void scale(Image srcImage, ImageOutputStream destImageStream, int width, int height, Color fixedColor) throws IORuntimeException {
|
public static void scale(Image srcImage, ImageOutputStream destImageStream, int width, int height, Color fixedColor) throws IORuntimeException {
|
||||||
@ -245,7 +246,7 @@ public class ImgUtil {
|
|||||||
* @param srcImage 源图像
|
* @param srcImage 源图像
|
||||||
* @param width 缩放后的宽度
|
* @param width 缩放后的宽度
|
||||||
* @param height 缩放后的高度
|
* @param height 缩放后的高度
|
||||||
* @param fixedColor 比例不对时补充的颜色,不补充为<code>null</code>
|
* @param fixedColor 比例不对时补充的颜色,不补充为{@code null}
|
||||||
* @return {@link Image}
|
* @return {@link Image}
|
||||||
*/
|
*/
|
||||||
public static Image scale(Image srcImage, int width, int height, Color fixedColor) {
|
public static Image scale(Image srcImage, int width, int height, Color fixedColor) {
|
||||||
@ -1641,6 +1642,17 @@ public class ImgUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从URL中获取或读取图片对象
|
||||||
|
*
|
||||||
|
* @param url URL
|
||||||
|
* @return {@link Image}
|
||||||
|
* @since 5.5.8
|
||||||
|
*/
|
||||||
|
public static Image getImage(URL url){
|
||||||
|
return Toolkit.getDefaultToolkit().getImage(url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从{@link Resource}中读取图片
|
* 从{@link Resource}中读取图片
|
||||||
*
|
*
|
||||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.ExecutorCompletionService;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -31,7 +32,7 @@ public class ThreadUtil {
|
|||||||
* @param corePoolSize 同时执行的线程数大小
|
* @param corePoolSize 同时执行的线程数大小
|
||||||
* @return ExecutorService
|
* @return ExecutorService
|
||||||
*/
|
*/
|
||||||
public static ExecutorService newExecutor(int corePoolSize) {
|
public static ExecutorService newExecutor(int corePoolSize) {
|
||||||
ExecutorBuilder builder = ExecutorBuilder.create();
|
ExecutorBuilder builder = ExecutorBuilder.create();
|
||||||
if (corePoolSize > 0) {
|
if (corePoolSize > 0) {
|
||||||
builder.setCorePoolSize(corePoolSize);
|
builder.setCorePoolSize(corePoolSize);
|
||||||
@ -540,4 +541,49 @@ public class ThreadUtil {
|
|||||||
public static ConcurrencyTester concurrencyTest(int threadSize, Runnable runnable) {
|
public static ConcurrencyTester concurrencyTest(int threadSize, Runnable runnable) {
|
||||||
return (new ConcurrencyTester(threadSize)).test(runnable);
|
return (new ConcurrencyTester(threadSize)).test(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建{@link ScheduledThreadPoolExecutor}
|
||||||
|
*
|
||||||
|
* @param corePoolSize 初始线程池大小
|
||||||
|
* @return {@link ScheduledThreadPoolExecutor}
|
||||||
|
* @since 5.5.8
|
||||||
|
*/
|
||||||
|
public static ScheduledThreadPoolExecutor createScheduledExecutor(int corePoolSize) {
|
||||||
|
return new ScheduledThreadPoolExecutor(corePoolSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始执行一个定时任务,执行方式分fixedRate模式和fixedDelay模式。
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>fixedRate 模式:下一次任务等待上一次任务执行完毕后再启动。</li>
|
||||||
|
* <li>fixedDelay模式:下一次任务不等待上一次任务,到周期自动执行。</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
||||||
|
* @param command 需要定时执行的逻辑
|
||||||
|
* @param initialDelay 初始延迟
|
||||||
|
* @param period 执行周期,单位毫秒
|
||||||
|
* @param fixedRateOrFixedDelay {@code true}表示fixedRate模式,{@code false}表示fixedDelay模式
|
||||||
|
* @return {@link ScheduledThreadPoolExecutor}
|
||||||
|
* @since 5.5.8
|
||||||
|
*/
|
||||||
|
public static ScheduledThreadPoolExecutor schedule(ScheduledThreadPoolExecutor executor,
|
||||||
|
Runnable command,
|
||||||
|
long initialDelay,
|
||||||
|
long period,
|
||||||
|
boolean fixedRateOrFixedDelay){
|
||||||
|
if(null == executor){
|
||||||
|
executor = createScheduledExecutor(2);
|
||||||
|
}
|
||||||
|
if(fixedRateOrFixedDelay){
|
||||||
|
executor.scheduleAtFixedRate(command, initialDelay, period, TimeUnit.NANOSECONDS);
|
||||||
|
} else{
|
||||||
|
executor.scheduleWithFixedDelay(command, initialDelay, period, TimeUnit.NANOSECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import org.junit.Assert;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CsvUtilTest {
|
public class CsvUtilTest {
|
||||||
@ -68,4 +69,22 @@ public class CsvUtilTest {
|
|||||||
Console.log(row);
|
Console.log(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void writeWrapTest(){
|
||||||
|
List<List<Object>> resultList=new ArrayList<>();
|
||||||
|
List<Object> list =new ArrayList<>();
|
||||||
|
list.add("\"name\"");
|
||||||
|
list.add("\"code\"");
|
||||||
|
resultList.add(list);
|
||||||
|
|
||||||
|
list =new ArrayList<>();
|
||||||
|
list.add("\"wang\"");
|
||||||
|
list.add(1);
|
||||||
|
resultList.add(list);
|
||||||
|
|
||||||
|
final CsvWriter writer = CsvUtil.getWriter("d:/test/csvWrapTest.csv", CharsetUtil.CHARSET_UTF_8);
|
||||||
|
writer.write(resultList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user