Skip to content

Commit

Permalink
修复图片操作未调用flush导致资源未释放问题
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Mar 28, 2024
1 parent abfa378 commit eebec03
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 127 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* 【core 】 修复DateUtil.betweenYear闰年2月问题(issue#I97U3J@Gitee)
* 【captcha】 修复Graphics2D的资源没释放问题(issue#I98PYN@Gitee)
* 【core 】 修复ClassUtil.getTypeArgument() 获取泛型存在null问题(issue#3516@Github)
* 【core 】 修复图片操作未调用flush导致资源未释放问题(issue#I9C7NA@Gitee)

-------------------------------------------------------------------------------------------------------------
# 5.8.26(2024-02-10)
Expand Down
14 changes: 9 additions & 5 deletions hutool-core/src/main/java/cn/hutool/core/img/Img.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.sun.imageio.plugins.common.ImageUtil;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
Expand All @@ -30,10 +31,7 @@
import java.awt.image.BufferedImage;
import java.awt.image.CropImageFilter;
import java.awt.image.ImageFilter;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.*;
import java.net.URL;
import java.nio.file.Path;

Expand All @@ -43,7 +41,7 @@
* @author looly
* @since 4.1.5
*/
public class Img implements Serializable {
public class Img implements Flushable, Serializable {
private static final long serialVersionUID = 1L;

private final BufferedImage srcImage;
Expand Down Expand Up @@ -754,6 +752,12 @@ public boolean write(File targetFile) throws IORuntimeException {
}
}

@Override
public void flush() {
ImgUtil.flush(this.srcImage);
ImgUtil.flush(this.targetImage);
}

// ---------------------------------------------------------------------------------------------------------------- Private method start

/**
Expand Down
Loading

0 comments on commit eebec03

Please sign in to comment.