Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: xiangbei.yzx <[email protected]>
  • Loading branch information
zhixiangyuan and xiangbei.yzx authored Aug 10, 2020
1 parent 3f2fefa commit a318abc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/main/java/run/halo/app/exception/ImageFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package run.halo.app.exception;

/**
* Image format exception.
*
* @author ZhiXiang Yuan
* @date 2020/08/10 02:11
*/
public class ImageFormatException extends BadRequestException {

public ImageFormatException(String message) {
super(message);
}

public ImageFormatException(String message, Throwable cause) {
super(message, cause);
}
}
7 changes: 6 additions & 1 deletion src/main/java/run/halo/app/utils/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import net.sf.image4j.codec.ico.ICODecoder;
import run.halo.app.exception.ImageFormatException;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
Expand All @@ -24,7 +25,11 @@ public static BufferedImage getImageFromFile(InputStream is, String extension) t
log.debug("Current File type is : [{}]", extension);

if (EXTENSION_ICO.equals(extension)) {
return ICODecoder.read(is).get(0);
try {
return ICODecoder.read(is).get(0);
} catch (IOException e) {
throw new ImageFormatException("ico 文件已损坏", e);
}
} else {
return ImageIO.read(is);
}
Expand Down

0 comments on commit a318abc

Please sign in to comment.