PoiWordFilter extends MediaFilter { @Override public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose) throws Exception { String text; try { POITextExtractor extractor = ExtractorFactory.createExtractor(source); text = extractor.getText(); } catch (IOException | OpenXML4JException | XmlException e) { System.err.format("Invalid File Format: %s%n", e.getMessage()); LOG.error("Unable to parse the bitstream: ", e); throw e; } if (verbose) { System.out.println(text); } return new ByteArrayInputStream(text.getBytes()); }  @Override String getFilteredName(String oldFilename); @Override String getBundleName(); @Override String getFormatString(); @Override String getDescription(); @Override InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose);  }
@Test public void testGetDestinationStreamDoc() throws Exception { System.out.println("getDestinationStream"); Item currentItem = null; InputStream source; boolean verbose = false; PoiWordFilter instance = new PoiWordFilter(); InputStream result; source = getClass().getResourceAsStream("wordtest.doc"); result = instance.getDestinationStream(currentItem, source, verbose); assertTrue("Known content was not found", readAll(result).contains("quick brown fox")); }
@Test public void testGetDestinationStreamDocx() throws Exception { System.out.println("getDestinationStream"); Item currentItem = null; InputStream source; boolean verbose = false; PoiWordFilter instance = new PoiWordFilter(); InputStream result; source = getClass().getResourceAsStream("wordtest.docx"); result = instance.getDestinationStream(currentItem, source, verbose); assertTrue("Known content was not found", readAll(result).contains("quick brown fox")); }