introduce getBufferedReadContentStream, comments

This commit is contained in:
millmanorama 2017-03-22 11:30:43 +01:00
parent 80abec5f13
commit 46ca7ee6a1

View File

@ -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> T getImageProperty(AbstractFile file, final String errorTemplate, PropertyExtractor<T> 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;
}