diff options
author | Vitaly Takmazov | 2018-08-09 18:21:51 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-08-09 18:21:51 +0300 |
commit | babb3a50a1c7e6101980a9577364b169b5c6654c (patch) | |
tree | 27f82bb04c79587bd9d844e916102eb6cc49d1ca /juick-common/src/main/java/com/juick/server/util | |
parent | 244c5aac19f19b64d4e066b1e66da72f704cf36a (diff) |
Fix attachments errors
Diffstat (limited to 'juick-common/src/main/java/com/juick/server/util')
-rw-r--r-- | juick-common/src/main/java/com/juick/server/util/ImageUtils.java | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/juick-common/src/main/java/com/juick/server/util/ImageUtils.java b/juick-common/src/main/java/com/juick/server/util/ImageUtils.java index d6a455a4..3e03314b 100644 --- a/juick-common/src/main/java/com/juick/server/util/ImageUtils.java +++ b/juick-common/src/main/java/com/juick/server/util/ImageUtils.java @@ -149,25 +149,24 @@ public class ImageUtils { } public Attachment getAttachment(File imgFile) throws IOException { Attachment attachment = new Attachment(); - int pos = imgFile.getName().lastIndexOf("."); - if (pos == -1) - throw new IOException("No extension for file: " + imgFile.getAbsolutePath()); - String suffix = imgFile.getName().substring(pos + 1); - Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix); - while(iter.hasNext()) { - ImageReader reader = iter.next(); - try (ImageInputStream stream = ImageIO.createImageInputStream(imgFile)) { - 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(); + 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(); + } } } - throw new IOException("Not a known image file: " + imgFile.getAbsolutePath()); + logger.warn("Not a known image file {}", imgFile.getAbsolutePath()); + return attachment; } }
\ No newline at end of file |