ImageContentReader extends ResourceContentReaderImpl<ImageContent> { @Override public ImageContent createFromContent(InputStream is, User user, Language language, long size, String fileName, String mimeType) throws IOException { ImageContent content = new ImageContentImpl(fileName, language, mimeType); content.setCreator(user); content.setCreationDate(new Date()); final byte[] imgData = IOUtils.toByteArray(is); try (final ByteArrayInputStream bais = new ByteArrayInputStream(imgData)) { BufferedImage bimg = ImageIO.read(bais); if (bimg != null) { content.setWidth(bimg.getWidth()); content.setHeight(bimg.getHeight()); } else { logger.warn("No ImageReader is able to read image '{}', dimensions could not be evaluated.", fileName); } } catch (Throwable t) { logger.error("Error extracting image dimensions from {}: {}", fileName, t.getMessage()); } try (final ByteArrayInputStream bais = new ByteArrayInputStream(imgData)) { readExifMetadata(content, bais); } catch (Throwable t) { logger.error("Error extracting Exif metadata from {}: {}", fileName, t.getMessage()); } return content; } ImageContentReader(); @Override ImageContent createFromXml(InputStream is); @Override ImageContent createFromContent(InputStream is, User user,
      Language language, long size, String fileName, String mimeType); void reset(); void startElement(String uri, String local, String raw,
      Attributes attrs); void endElement(String uri, String local, String raw);  }
@Test public void testCreateFromContent() throws Exception { InputStream is = ImageContentReaderTest.class.getResourceAsStream("/" + fileName); ImageContent content = reader.createFromContent(is, user, language, size, fileName, mimeType); assertEquals(imageWidth, content.getWidth()); assertEquals(imageHeight, content.getHeight()); }