aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/util/ImageUtils.java31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/main/java/com/juick/util/ImageUtils.java b/src/main/java/com/juick/util/ImageUtils.java
index d2158cca..3549a89a 100644
--- a/src/main/java/com/juick/util/ImageUtils.java
+++ b/src/main/java/com/juick/util/ImageUtils.java
@@ -150,21 +150,26 @@ public class ImageUtils {
}
public Attachment getAttachment(File imgFile) throws IOException {
Attachment attachment = new Attachment();
- try (ImageInputStream stream = ImageIO.createImageInputStream(imgFile)) {
- Iterator<ImageReader> iter = ImageIO.getImageReaders(stream);
- while (iter.hasNext()) {
- ImageReader reader = iter.next();
- try {
- reader.setInput(stream);
- attachment.setWidth(reader.getWidth(reader.getMinIndex()));
- attachment.setHeight(reader.getHeight(reader.getMinIndex()));
- return attachment;
- } catch (Exception e) {
- logger.debug("Error reading {}, trying next reader", imgFile.getAbsolutePath());
- } finally {
- reader.dispose();
+ if (imgFile.exists()) {
+ try (ImageInputStream stream = ImageIO.createImageInputStream(imgFile)) {
+ Iterator<ImageReader> iter = ImageIO.getImageReaders(stream);
+ while (iter.hasNext()) {
+ ImageReader reader = iter.next();
+ try {
+ reader.setInput(stream);
+ attachment.setWidth(reader.getWidth(reader.getMinIndex()));
+ attachment.setHeight(reader.getHeight(reader.getMinIndex()));
+ return attachment;
+ } catch (Exception e) {
+ logger.debug("Error reading {}, trying next reader", imgFile.getAbsolutePath());
+ } finally {
+ reader.dispose();
+ }
}
}
+ } else {
+ logger.warn("File not exists yet: {}", imgFile.getAbsolutePath());
+ return attachment;
}
logger.warn("Not a known image file {}", imgFile.getAbsolutePath());