TSDParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try (RereadableInputStream ris = new RereadableInputStream(stream, 2048, true, true)) { Metadata TSDAndEmbeddedMetadata = new Metadata(); List<TSDMetas> tsdMetasList = this.extractMetas(ris); this.buildMetas(tsdMetasList, metadata != null && metadata.size() > 0 ? TSDAndEmbeddedMetadata : metadata); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); ris.rewind(); this.parseTSDContent(ris, xhtml, TSDAndEmbeddedMetadata, context); xhtml.endDocument(); } }  @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler,
                      Metadata metadata, ParseContext context); static final String TSD_MIME_TYPE; }
@Test public void testTSDFileData() throws Exception { try (InputStream inputXml = TSDParserTest.class.getResourceAsStream("/test-documents/MANIFEST.XML.TSD"); InputStream inputTxt1 = TSDParserTest.class.getResourceAsStream("/test-documents/Test1.txt.tsd"); InputStream inputTxt2 = TSDParserTest.class.getResourceAsStream("/test-documents/Test2.txt.tsd"); InputStream inputDocx = TSDParserTest.class.getResourceAsStream("/test-documents/Test3.docx.tsd"); InputStream inputPdf = TSDParserTest.class.getResourceAsStream("/test-documents/Test4.pdf.tsd"); InputStream inputPng = TSDParserTest.class.getResourceAsStream("/test-documents/Test5.PNG.tsd");) { TSDParser tsdParser = new TSDParser(); ContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); ParseContext parseContext = new ParseContext(); tsdParser.parse(inputXml, handler, metadata, parseContext); assertNotNull(handler); assertNotNull(metadata); assertContains("Description=Time Stamped Data Envelope", metadata.toString()); assertContains("Content-Type=application/timestamped-data", metadata.toString()); assertContains("File-Parsed=true", metadata.toString()); handler = new BodyContentHandler(); metadata = new Metadata(); parseContext = new ParseContext(); tsdParser.parse(inputTxt1, handler, metadata, parseContext); assertNotNull(handler); assertNotNull(metadata); assertContains("Description=Time Stamped Data Envelope", metadata.toString()); assertContains("Content-Type=application/timestamped-data", metadata.toString()); assertContains("File-Parsed=true", metadata.toString()); handler = new BodyContentHandler(); metadata = new Metadata(); parseContext = new ParseContext(); tsdParser.parse(inputTxt2, handler, metadata, parseContext); assertNotNull(handler); assertNotNull(metadata); assertContains("Description=Time Stamped Data Envelope", metadata.toString()); assertContains("Content-Type=application/timestamped-data", metadata.toString()); assertContains("File-Parsed=true", metadata.toString()); handler = new BodyContentHandler(); metadata = new Metadata(); parseContext = new ParseContext(); tsdParser.parse(inputDocx, handler, metadata, parseContext); assertNotNull(handler); assertNotNull(metadata); assertContains("Description=Time Stamped Data Envelope", metadata.toString()); assertContains("Content-Type=application/timestamped-data", metadata.toString()); assertContains("File-Parsed=true", metadata.toString()); handler = new BodyContentHandler(); metadata = new Metadata(); parseContext = new ParseContext(); tsdParser.parse(inputPdf, handler, metadata, parseContext); assertNotNull(handler); assertNotNull(metadata); assertContains("Description=Time Stamped Data Envelope", metadata.toString()); assertContains("Content-Type=application/timestamped-data", metadata.toString()); assertContains("File-Parsed=true", metadata.toString()); handler = new BodyContentHandler(); metadata = new Metadata(); parseContext = new ParseContext(); tsdParser.parse(inputPng, handler, metadata, parseContext); assertNotNull(handler); assertNotNull(metadata); assertContains("Description=Time Stamped Data Envelope", metadata.toString()); assertContains("Content-Type=application/timestamped-data", metadata.toString()); assertContains("File-Parsed=true", metadata.toString()); } }