List of usage examples for javax.imageio IIOException toString
public String toString()
From source file:org.sleuthkit.autopsy.coreutils.ImageUtils.java
/** * Private template method designed to be used as the implementation of * public methods that pull particular (usually meta-)data out of a image * file.// www. j a v a2 s. co m * * @param file the file to extract the data from * @param errorTemplate a message template used to log errors. Should * take one parameter: the file's unique path or * name. * @param propertyExtractor an implementation of {@link PropertyExtractor} * used to retrieve the specific property. * * @return the the value of the property extracted by the given * propertyExtractor * * @throws IOException if there was a problem reading the property from the * file. * * @see PropertyExtractor * @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 (ImageInputStream input = ImageIO.createImageInputStream(inputStream)) { if (input == null) { IIOException iioException = new IIOException("Could not create ImageInputStream."); LOGGER.log(Level.WARNING, errorTemplate + iioException.toString(), getContentPathSafe(file)); throw iioException; } Iterator<ImageReader> readers = ImageIO.getImageReaders(input); if (readers.hasNext()) { ImageReader reader = readers.next(); reader.setInput(input); try { return propertyExtractor.extract(reader); } catch (IOException ex) { LOGGER.log(Level.WARNING, errorTemplate + ex.toString(), getContentPathSafe(file)); throw ex; } finally { reader.dispose(); } } else { IIOException iioException = new IIOException("No ImageReader found."); LOGGER.log(Level.WARNING, errorTemplate + iioException.toString(), getContentPathSafe(file)); throw iioException; } } } }