From 46ca7ee6a1ff644a4a23686e03a13cf718aedcce Mon Sep 17 00:00:00 2001 From: millmanorama Date: Wed, 22 Mar 2017 11:30:43 +0100 Subject: [PATCH] introduce getBufferedReadContentStream, comments --- .../autopsy/coreutils/ImageUtils.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index 6f2dd5e77e..3c508f0304 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -297,15 +297,19 @@ public class ImageUtils { * @param content the content to generate a thumbnail for * @param iconSize the size (one side of a square) in pixels to generate * - * @return a thumbnail for the given image or a default one if there was a + * @return A thumbnail for the given image or a default one if there was a * problem making a thumbnail. */ public static BufferedImage getThumbnail(Content content, int iconSize) { if (content instanceof AbstractFile) { AbstractFile file = (AbstractFile) content; if (ImageUtils.isGIF(file)) { + /* + * Intercepting the image reading code for GIFs here allows us + * to rescale easily, but we lose animations. + */ try { - return ScalrWrapper.resizeHighQuality(ImageIO.read(new BufferedInputStream(new ReadContentInputStream(file))), iconSize, iconSize); + return ScalrWrapper.resizeHighQuality(ImageIO.read(getBufferedReadContentStream(file)), iconSize, iconSize); } catch (IOException iOException) { LOGGER.log(Level.WARNING, "Failed to get thumbnail for " + getContentPathSafe(content), iOException); //NON-NLS return DEFAULT_THUMBNAIL; @@ -325,6 +329,19 @@ public class ImageUtils { } } + /** + * Get a BufferedInputStream wrapped around a ReadContentStream for the + * given AbstractFile. + * + * @param file The AbstractFile to get a stream for. + * + * @return A BufferedInputStream wrapped around a ReadContentStream for the + * given AbstractFile + */ + private static BufferedInputStream getBufferedReadContentStream(AbstractFile file) { + return new BufferedInputStream(new ReadContentInputStream(file)); + } + /** * Get a thumbnail of a specified size for the given image. Generates the * thumbnail if it is not already cached. @@ -550,7 +567,7 @@ public class ImageUtils { * @see #getImageHeight(org.sleuthkit.datamodel.AbstractFile) */ private static T getImageProperty(AbstractFile file, final String errorTemplate, PropertyExtractor propertyExtractor) throws IOException { - try (InputStream inputStream = new BufferedInputStream(new ReadContentInputStream(file));) { + try (InputStream inputStream = getBufferedReadContentStream(file);) { try (ImageInputStream input = ImageIO.createImageInputStream(inputStream)) { if (input == null) { IIOException iioException = new IIOException("Could not create ImageInputStream."); @@ -793,7 +810,7 @@ public class ImageUtils { protected javafx.scene.image.Image readImage() throws IOException { if (ImageUtils.isGIF(file)) { //use JavaFX to directly read GIF to preserve potential animation - javafx.scene.image.Image image = new javafx.scene.image.Image(new BufferedInputStream(new ReadContentInputStream(file))); + javafx.scene.image.Image image = new javafx.scene.image.Image(getBufferedReadContentStream(file)); if (image.isError() == false) { return image; }