@Test public void testTikaProvider() throws IOException { log.info("testTikaProvider"); TikaFallbackProvider tfp = new TikaFallbackProvider(); assertNotNull(tfp.getThumbnail(docxFile)); }
@Override public InputStream getThumbnail(Resource resource) throws IOException { log.info("Extracting content thumbnail from {}", resource.getPath()); try { log.debug("Extracting file contents"); String contents = extractContents(resource); log.debug("Creating thumbnail of file contents"); int width = 500; int height = 500; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); JEditorPane jep = new JEditorPane("text/html", contents); jep.setSize(width, height); jep.print(graphics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } catch (SAXException | TikaException e) { throw new IOException("Failed to generate thumbnail from " + resource.getPath(), e); } }
TikaFallbackProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { log.info("Extracting content thumbnail from {}", resource.getPath()); try { log.debug("Extracting file contents"); String contents = extractContents(resource); log.debug("Creating thumbnail of file contents"); int width = 500; int height = 500; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); JEditorPane jep = new JEditorPane("text/html", contents); jep.setSize(width, height); jep.print(graphics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } catch (SAXException | TikaException e) { throw new IOException("Failed to generate thumbnail from " + resource.getPath(), e); } } }
TikaFallbackProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { log.info("Extracting content thumbnail from {}", resource.getPath()); try { log.debug("Extracting file contents"); String contents = extractContents(resource); log.debug("Creating thumbnail of file contents"); int width = 500; int height = 500; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); JEditorPane jep = new JEditorPane("text/html", contents); jep.setSize(width, height); jep.print(graphics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } catch (SAXException | TikaException e) { throw new IOException("Failed to generate thumbnail from " + resource.getPath(), e); } }  }
TikaFallbackProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { log.info("Extracting content thumbnail from {}", resource.getPath()); try { log.debug("Extracting file contents"); String contents = extractContents(resource); log.debug("Creating thumbnail of file contents"); int width = 500; int height = 500; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); JEditorPane jep = new JEditorPane("text/html", contents); jep.setSize(width, height); jep.print(graphics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } catch (SAXException | TikaException e) { throw new IOException("Failed to generate thumbnail from " + resource.getPath(), e); } }  @Override boolean applies(Resource resource); @Override InputStream getThumbnail(Resource resource); }
TikaFallbackProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { log.info("Extracting content thumbnail from {}", resource.getPath()); try { log.debug("Extracting file contents"); String contents = extractContents(resource); log.debug("Creating thumbnail of file contents"); int width = 500; int height = 500; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); JEditorPane jep = new JEditorPane("text/html", contents); jep.setSize(width, height); jep.print(graphics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } catch (SAXException | TikaException e) { throw new IOException("Failed to generate thumbnail from " + resource.getPath(), e); } }  @Override boolean applies(Resource resource); @Override InputStream getThumbnail(Resource resource);  }