@Test public void testEncryptedRar() throws Exception { Parser parser = new RarParser(); try (InputStream input = RarParserTest.class.getResourceAsStream( "/test-documents/test-documents-enc.rar")) { Metadata metadata = new Metadata(); ContentHandler handler = new BodyContentHandler(); ParseContext context = new ParseContext(); context.set(PasswordProvider.class, new PasswordProvider() { @Override public String getPassword(Metadata metadata) { return "ApacheTika"; } }); parser.parse(input, handler, metadata, trackingContext); fail("No support yet for Encrypted RAR files"); } catch (EncryptedDocumentException e) { } }
@Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); String mediaType = metadata.get(Metadata.CONTENT_TYPE); if (mediaType != null && mediaType.contains("version=5")) { throw new UnsupportedFormatException("Tika does not yet support rar version 5."); } Archive rar = null; try (TemporaryResources tmp = new TemporaryResources()) { TikaInputStream tis = TikaInputStream.get(stream, tmp); rar = new Archive(tis.getFile()); if (rar.isEncrypted()) { throw new EncryptedDocumentException(); } xhtml.element("div", " "); FileHeader header = rar.nextFileHeader(); while (header != null && !Thread.currentThread().isInterrupted()) { if (!header.isDirectory()) { try (InputStream subFile = rar.getInputStream(header)) { Metadata entrydata = PackageParser.handleEntryMetadata( "".equals(header.getFileNameW()) ? header.getFileNameString() : header.getFileNameW(), header.getCTime(), header.getMTime(), header.getFullUnpackSize(), xhtml ); if (extractor.shouldParseEmbedded(entrydata)) { extractor.parseEmbedded(subFile, handler, entrydata, true); } } } header = rar.nextFileHeader(); } } catch (RarException e) { throw new TikaException("RarParser Exception", e); } finally { if (rar != null) rar.close(); } xhtml.endDocument(); }
RarParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); String mediaType = metadata.get(Metadata.CONTENT_TYPE); if (mediaType != null && mediaType.contains("version=5")) { throw new UnsupportedFormatException("Tika does not yet support rar version 5."); } Archive rar = null; try (TemporaryResources tmp = new TemporaryResources()) { TikaInputStream tis = TikaInputStream.get(stream, tmp); rar = new Archive(tis.getFile()); if (rar.isEncrypted()) { throw new EncryptedDocumentException(); } xhtml.element("div", " "); FileHeader header = rar.nextFileHeader(); while (header != null && !Thread.currentThread().isInterrupted()) { if (!header.isDirectory()) { try (InputStream subFile = rar.getInputStream(header)) { Metadata entrydata = PackageParser.handleEntryMetadata( "".equals(header.getFileNameW()) ? header.getFileNameString() : header.getFileNameW(), header.getCTime(), header.getMTime(), header.getFullUnpackSize(), xhtml ); if (extractor.shouldParseEmbedded(entrydata)) { extractor.parseEmbedded(subFile, handler, entrydata, true); } } } header = rar.nextFileHeader(); } } catch (RarException e) { throw new TikaException("RarParser Exception", e); } finally { if (rar != null) rar.close(); } xhtml.endDocument(); } }
RarParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); String mediaType = metadata.get(Metadata.CONTENT_TYPE); if (mediaType != null && mediaType.contains("version=5")) { throw new UnsupportedFormatException("Tika does not yet support rar version 5."); } Archive rar = null; try (TemporaryResources tmp = new TemporaryResources()) { TikaInputStream tis = TikaInputStream.get(stream, tmp); rar = new Archive(tis.getFile()); if (rar.isEncrypted()) { throw new EncryptedDocumentException(); } xhtml.element("div", " "); FileHeader header = rar.nextFileHeader(); while (header != null && !Thread.currentThread().isInterrupted()) { if (!header.isDirectory()) { try (InputStream subFile = rar.getInputStream(header)) { Metadata entrydata = PackageParser.handleEntryMetadata( "".equals(header.getFileNameW()) ? header.getFileNameString() : header.getFileNameW(), header.getCTime(), header.getMTime(), header.getFullUnpackSize(), xhtml ); if (extractor.shouldParseEmbedded(entrydata)) { extractor.parseEmbedded(subFile, handler, entrydata, true); } } } header = rar.nextFileHeader(); } } catch (RarException e) { throw new TikaException("RarParser Exception", e); } finally { if (rar != null) rar.close(); } xhtml.endDocument(); }  }
RarParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); String mediaType = metadata.get(Metadata.CONTENT_TYPE); if (mediaType != null && mediaType.contains("version=5")) { throw new UnsupportedFormatException("Tika does not yet support rar version 5."); } Archive rar = null; try (TemporaryResources tmp = new TemporaryResources()) { TikaInputStream tis = TikaInputStream.get(stream, tmp); rar = new Archive(tis.getFile()); if (rar.isEncrypted()) { throw new EncryptedDocumentException(); } xhtml.element("div", " "); FileHeader header = rar.nextFileHeader(); while (header != null && !Thread.currentThread().isInterrupted()) { if (!header.isDirectory()) { try (InputStream subFile = rar.getInputStream(header)) { Metadata entrydata = PackageParser.handleEntryMetadata( "".equals(header.getFileNameW()) ? header.getFileNameString() : header.getFileNameW(), header.getCTime(), header.getMTime(), header.getFullUnpackSize(), xhtml ); if (extractor.shouldParseEmbedded(entrydata)) { extractor.parseEmbedded(subFile, handler, entrydata, true); } } } header = rar.nextFileHeader(); } } catch (RarException e) { throw new TikaException("RarParser Exception", e); } finally { if (rar != null) rar.close(); } xhtml.endDocument(); }  @Override Set<MediaType> getSupportedTypes(ParseContext arg0); @Override void parse(InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); }
RarParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); EmbeddedDocumentExtractor extractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); String mediaType = metadata.get(Metadata.CONTENT_TYPE); if (mediaType != null && mediaType.contains("version=5")) { throw new UnsupportedFormatException("Tika does not yet support rar version 5."); } Archive rar = null; try (TemporaryResources tmp = new TemporaryResources()) { TikaInputStream tis = TikaInputStream.get(stream, tmp); rar = new Archive(tis.getFile()); if (rar.isEncrypted()) { throw new EncryptedDocumentException(); } xhtml.element("div", " "); FileHeader header = rar.nextFileHeader(); while (header != null && !Thread.currentThread().isInterrupted()) { if (!header.isDirectory()) { try (InputStream subFile = rar.getInputStream(header)) { Metadata entrydata = PackageParser.handleEntryMetadata( "".equals(header.getFileNameW()) ? header.getFileNameString() : header.getFileNameW(), header.getCTime(), header.getMTime(), header.getFullUnpackSize(), xhtml ); if (extractor.shouldParseEmbedded(entrydata)) { extractor.parseEmbedded(subFile, handler, entrydata, true); } } } header = rar.nextFileHeader(); } } catch (RarException e) { throw new TikaException("RarParser Exception", e); } finally { if (rar != null) rar.close(); } xhtml.endDocument(); }  @Override Set<MediaType> getSupportedTypes(ParseContext arg0); @Override void parse(InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context);  }