@Test public void testSpecializations() throws Exception { TikaConfig config = TikaConfig.getDefaultConfig(); MediaTypeRegistry mediaTypeRegistry = config.getMimeRepository().getMediaTypeRegistry(); Set<MediaType> currentSpecializations = new HashSet<>(); MediaType tar = MediaType.parse("application/x-tar"); for (MediaType type : mediaTypeRegistry.getTypes()) { if (mediaTypeRegistry.isSpecializationOf(type, MediaType.APPLICATION_ZIP) || mediaTypeRegistry.isSpecializationOf(type, tar)) { currentSpecializations.add(type); } } for (MediaType mediaType : currentSpecializations) { assertTrue("missing: "+mediaType, PackageParser.PACKAGE_SPECIALIZATIONS.contains(mediaType)); } assertEquals(currentSpecializations.size(), PackageParser.PACKAGE_SPECIALIZATIONS.size()); }
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (! stream.markSupported()) { stream = new BufferedInputStream(stream); } TemporaryResources tmp = new TemporaryResources(); ArchiveInputStream ais = null; String encoding = null; try { ArchiveStreamFactory factory = context.get(ArchiveStreamFactory.class, new ArchiveStreamFactory()); encoding = factory.getEntryEncoding(); ais = factory.createArchiveInputStream(new CloseShieldInputStream(stream)); } catch (StreamingNotSupportedException sne) { if (sne.getFormat().equals(ArchiveStreamFactory.SEVEN_Z)) { stream.reset(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); String password = null; PasswordProvider provider = context.get(PasswordProvider.class); if (provider != null) { password = provider.getPassword(metadata); } SevenZFile sevenz; try{ if (password == null) { sevenz = new SevenZFile(tstream.getFile()); } else { sevenz = new SevenZFile(tstream.getFile(), password.getBytes("UnicodeLittleUnmarked")); } }catch(PasswordRequiredException e){ throw new EncryptedDocumentException(e); } ais = new SevenZWrapper(sevenz); } else { tmp.close(); throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne); } } catch (ArchiveException e) { tmp.close(); throw new TikaException("Unable to unpack document stream", e); } updateMediaType(ais, metadata); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); stream.mark(MARK_LIMIT); AtomicInteger entryCnt = new AtomicInteger(); try { parseEntries(ais, metadata, extractor, xhtml, false, entryCnt); } catch (UnsupportedZipFeatureException zfe) { if (zfe.getFeature() == Feature.DATA_DESCRIPTOR) { ais.close(); stream.reset(); ais = new ZipArchiveInputStream(new CloseShieldInputStream(stream), encoding, true, true); parseEntries(ais, metadata, extractor, xhtml, true, entryCnt); } } finally { ais.close(); tmp.close(); } xhtml.endDocument(); }
PackageParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (! stream.markSupported()) { stream = new BufferedInputStream(stream); } TemporaryResources tmp = new TemporaryResources(); ArchiveInputStream ais = null; String encoding = null; try { ArchiveStreamFactory factory = context.get(ArchiveStreamFactory.class, new ArchiveStreamFactory()); encoding = factory.getEntryEncoding(); ais = factory.createArchiveInputStream(new CloseShieldInputStream(stream)); } catch (StreamingNotSupportedException sne) { if (sne.getFormat().equals(ArchiveStreamFactory.SEVEN_Z)) { stream.reset(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); String password = null; PasswordProvider provider = context.get(PasswordProvider.class); if (provider != null) { password = provider.getPassword(metadata); } SevenZFile sevenz; try{ if (password == null) { sevenz = new SevenZFile(tstream.getFile()); } else { sevenz = new SevenZFile(tstream.getFile(), password.getBytes("UnicodeLittleUnmarked")); } }catch(PasswordRequiredException e){ throw new EncryptedDocumentException(e); } ais = new SevenZWrapper(sevenz); } else { tmp.close(); throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne); } } catch (ArchiveException e) { tmp.close(); throw new TikaException("Unable to unpack document stream", e); } updateMediaType(ais, metadata); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); stream.mark(MARK_LIMIT); AtomicInteger entryCnt = new AtomicInteger(); try { parseEntries(ais, metadata, extractor, xhtml, false, entryCnt); } catch (UnsupportedZipFeatureException zfe) { if (zfe.getFeature() == Feature.DATA_DESCRIPTOR) { ais.close(); stream.reset(); ais = new ZipArchiveInputStream(new CloseShieldInputStream(stream), encoding, true, true); parseEntries(ais, metadata, extractor, xhtml, true, entryCnt); } } finally { ais.close(); tmp.close(); } xhtml.endDocument(); } }
PackageParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (! stream.markSupported()) { stream = new BufferedInputStream(stream); } TemporaryResources tmp = new TemporaryResources(); ArchiveInputStream ais = null; String encoding = null; try { ArchiveStreamFactory factory = context.get(ArchiveStreamFactory.class, new ArchiveStreamFactory()); encoding = factory.getEntryEncoding(); ais = factory.createArchiveInputStream(new CloseShieldInputStream(stream)); } catch (StreamingNotSupportedException sne) { if (sne.getFormat().equals(ArchiveStreamFactory.SEVEN_Z)) { stream.reset(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); String password = null; PasswordProvider provider = context.get(PasswordProvider.class); if (provider != null) { password = provider.getPassword(metadata); } SevenZFile sevenz; try{ if (password == null) { sevenz = new SevenZFile(tstream.getFile()); } else { sevenz = new SevenZFile(tstream.getFile(), password.getBytes("UnicodeLittleUnmarked")); } }catch(PasswordRequiredException e){ throw new EncryptedDocumentException(e); } ais = new SevenZWrapper(sevenz); } else { tmp.close(); throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne); } } catch (ArchiveException e) { tmp.close(); throw new TikaException("Unable to unpack document stream", e); } updateMediaType(ais, metadata); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); stream.mark(MARK_LIMIT); AtomicInteger entryCnt = new AtomicInteger(); try { parseEntries(ais, metadata, extractor, xhtml, false, entryCnt); } catch (UnsupportedZipFeatureException zfe) { if (zfe.getFeature() == Feature.DATA_DESCRIPTOR) { ais.close(); stream.reset(); ais = new ZipArchiveInputStream(new CloseShieldInputStream(stream), encoding, true, true); parseEntries(ais, metadata, extractor, xhtml, true, entryCnt); } } finally { ais.close(); tmp.close(); } xhtml.endDocument(); }  }
PackageParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (! stream.markSupported()) { stream = new BufferedInputStream(stream); } TemporaryResources tmp = new TemporaryResources(); ArchiveInputStream ais = null; String encoding = null; try { ArchiveStreamFactory factory = context.get(ArchiveStreamFactory.class, new ArchiveStreamFactory()); encoding = factory.getEntryEncoding(); ais = factory.createArchiveInputStream(new CloseShieldInputStream(stream)); } catch (StreamingNotSupportedException sne) { if (sne.getFormat().equals(ArchiveStreamFactory.SEVEN_Z)) { stream.reset(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); String password = null; PasswordProvider provider = context.get(PasswordProvider.class); if (provider != null) { password = provider.getPassword(metadata); } SevenZFile sevenz; try{ if (password == null) { sevenz = new SevenZFile(tstream.getFile()); } else { sevenz = new SevenZFile(tstream.getFile(), password.getBytes("UnicodeLittleUnmarked")); } }catch(PasswordRequiredException e){ throw new EncryptedDocumentException(e); } ais = new SevenZWrapper(sevenz); } else { tmp.close(); throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne); } } catch (ArchiveException e) { tmp.close(); throw new TikaException("Unable to unpack document stream", e); } updateMediaType(ais, metadata); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); stream.mark(MARK_LIMIT); AtomicInteger entryCnt = new AtomicInteger(); try { parseEntries(ais, metadata, extractor, xhtml, false, entryCnt); } catch (UnsupportedZipFeatureException zfe) { if (zfe.getFeature() == Feature.DATA_DESCRIPTOR) { ais.close(); stream.reset(); ais = new ZipArchiveInputStream(new CloseShieldInputStream(stream), encoding, true, true); parseEntries(ais, metadata, extractor, xhtml, true, entryCnt); } } finally { ais.close(); tmp.close(); } xhtml.endDocument(); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); }
PackageParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (! stream.markSupported()) { stream = new BufferedInputStream(stream); } TemporaryResources tmp = new TemporaryResources(); ArchiveInputStream ais = null; String encoding = null; try { ArchiveStreamFactory factory = context.get(ArchiveStreamFactory.class, new ArchiveStreamFactory()); encoding = factory.getEntryEncoding(); ais = factory.createArchiveInputStream(new CloseShieldInputStream(stream)); } catch (StreamingNotSupportedException sne) { if (sne.getFormat().equals(ArchiveStreamFactory.SEVEN_Z)) { stream.reset(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); String password = null; PasswordProvider provider = context.get(PasswordProvider.class); if (provider != null) { password = provider.getPassword(metadata); } SevenZFile sevenz; try{ if (password == null) { sevenz = new SevenZFile(tstream.getFile()); } else { sevenz = new SevenZFile(tstream.getFile(), password.getBytes("UnicodeLittleUnmarked")); } }catch(PasswordRequiredException e){ throw new EncryptedDocumentException(e); } ais = new SevenZWrapper(sevenz); } else { tmp.close(); throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne); } } catch (ArchiveException e) { tmp.close(); throw new TikaException("Unable to unpack document stream", e); } updateMediaType(ais, metadata); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); stream.mark(MARK_LIMIT); AtomicInteger entryCnt = new AtomicInteger(); try { parseEntries(ais, metadata, extractor, xhtml, false, entryCnt); } catch (UnsupportedZipFeatureException zfe) { if (zfe.getFeature() == Feature.DATA_DESCRIPTOR) { ais.close(); stream.reset(); ais = new ZipArchiveInputStream(new CloseShieldInputStream(stream), encoding, true, true); parseEntries(ais, metadata, extractor, xhtml, true, entryCnt); } } finally { ais.close(); tmp.close(); } xhtml.endDocument(); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context);  }