org.apache.tika.Tika.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(264)

本文整理了Java中org.apache.tika.Tika.<init>()方法的一些代码示例,展示了Tika.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tika.<init>()方法的具体详情如下:
包路径:org.apache.tika.Tika
类名称:Tika
方法名:<init>

Tika.<init>介绍

[英]Creates a Tika facade using the default configuration.
[中]使用默认配置创建Tika facade。

代码示例

代码示例来源:origin: stackoverflow.com

  1. Tika tika = new Tika();
  2. File file = ...
  3. String mimeType = tika.detect(file);

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. protected void getMimeType(InputStream inputStream, String fileName, StaticAsset newAsset) {
  2. Tika tika = new Tika();
  3. String tikaMimeType = tika.detect(fileName);
  4. if (tikaMimeType == null) {
  5. try {
  6. tikaMimeType = tika.detect(inputStream);
  7. } catch (IOException e) {
  8. //if tika can't resolve, don't throw exception
  9. }
  10. }
  11. if (tikaMimeType != null) {
  12. newAsset.setMimeType(tikaMimeType);
  13. }
  14. }

代码示例来源:origin: apache/tika

  1. public static void main(String[] args) throws Exception {
  2. // Create a Tika instance with the default configuration
  3. Tika tika = new Tika();
  4. // Parse all given files and print out the extracted
  5. // text content
  6. for (String file : args) {
  7. String text = tika.parseToString(new File(file));
  8. System.out.print(text);
  9. }
  10. }
  11. }

代码示例来源:origin: apache/tika

  1. public static void main(String[] args) throws Exception {
  2. Tika tika = new Tika();
  3. for (String file : args) {
  4. String type = tika.detect(new File(file));
  5. System.out.println(file + ": " + type);
  6. }
  7. }
  8. }

代码示例来源:origin: apache/tika

  1. public static String parseToStringExample() throws Exception {
  2. File document = new File("example.doc");
  3. String content = new Tika().parseToString(document);
  4. System.out.print(content);
  5. return content;
  6. }

代码示例来源:origin: apache/tika

  1. public static void parseToReaderExample() throws Exception {
  2. File document = new File("example.doc");
  3. try (Reader reader = new Tika().parse(document)) {
  4. char[] buffer = new char[1000];
  5. int n = reader.read(buffer);
  6. while (n != -1) {
  7. System.out.append(CharBuffer.wrap(buffer, 0, n));
  8. n = reader.read(buffer);
  9. }
  10. }
  11. }

代码示例来源:origin: apache/tika

  1. public static void main(String[] args) {
  2. LOG.info("Starting {} server", new Tika());
  3. try {
  4. execute(args);
  5. } catch (Exception e) {
  6. e.printStackTrace();
  7. LOG.error("Can't start: ", e);
  8. System.exit(-1);
  9. }
  10. }

代码示例来源:origin: apache/tika

  1. public static void main(String[] args) throws Exception {
  2. IndexWriterConfig indexWriterConfig = new IndexWriterConfig(new StandardAnalyzer());
  3. try (IndexWriter writer =
  4. new IndexWriter(FSDirectory.open(Paths.get(args[0])),
  5. indexWriterConfig)) {
  6. LuceneIndexer indexer = new LuceneIndexer(new Tika(), writer);
  7. for (int i = 1; i < args.length; i++) {
  8. indexer.indexDocument(new File(args[i]));
  9. }
  10. }
  11. }

代码示例来源:origin: apache/tika

  1. public TikaVersion() {
  2. this.tika = new Tika(TikaResource.getConfig());
  3. }

代码示例来源:origin: apache/tika

  1. private void version() {
  2. System.out.println(new Tika().toString());
  3. }

代码示例来源:origin: apache/tika

  1. public static String customMimeInfo() throws Exception {
  2. String path = "file:///path/to/prescription-type.xml";
  3. MimeTypes typeDatabase = MimeTypesFactory.create(new URL(path));
  4. Tika tika = new Tika(typeDatabase);
  5. String type = tika.detect("/path/to/prescription.xpd");
  6. return type;
  7. }

代码示例来源:origin: apache/tika

  1. public AgeRecogniser() {
  2. try {
  3. secondaryParser = new Tika(new TikaConfig());
  4. available = true;
  5. } catch (Exception e) {
  6. available = false;
  7. LOG.log(Level.SEVERE, "Unable to initialize secondary parser");
  8. }
  9. }

代码示例来源:origin: apache/tika

  1. public static String detectWithCustomConfig(String name) throws Exception {
  2. String config = "/org/apache/tika/mime/tika-mimetypes.xml";
  3. Tika tika = new Tika(MimeTypesFactory.create(config));
  4. return tika.detect(name);
  5. }

代码示例来源:origin: apache/tika

  1. public TikaWelcome(List<ResourceProvider> rCoreProviders) {
  2. this.tika = new Tika(TikaResource.getConfig());
  3. this.html = new HTMLHelper();
  4. for (ResourceProvider rp : rCoreProviders) {
  5. this.endpoints.add(rp.getResourceClass());
  6. }
  7. }

代码示例来源:origin: apache/tika

  1. public TrecDocument summarize(File file) throws FileNotFoundException,
  2. IOException, TikaException {
  3. Tika tika = new Tika();
  4. Metadata met = new Metadata();
  5. String contents = tika.parseToString(new FileInputStream(file), met);
  6. return new TrecDocument(met.get(TikaCoreProperties.RESOURCE_NAME_KEY), contents,
  7. met.getDate(TikaCoreProperties.CREATED));
  8. }

代码示例来源:origin: apache/tika

  1. public static String customCompositeDetector() throws Exception {
  2. String path = "file:///path/to/prescription-type.xml";
  3. MimeTypes typeDatabase = MimeTypesFactory.create(new URL(path));
  4. Tika tika = new Tika(new CompositeDetector(typeDatabase,
  5. new EncryptedPrescriptionDetector()));
  6. String type = tika.detect("/path/to/tmp/prescription.xpd");
  7. return type;
  8. }

代码示例来源:origin: apache/tika

  1. private Metadata getMetadata(String name) throws TikaException, IOException, SAXException {
  2. URL url = this.getClass().getResource("/org/apache/tika/config/"+name);
  3. assertNotNull("couldn't find: "+name, url);
  4. TikaConfig tikaConfig = new TikaConfig(url);
  5. Tika tika = new Tika(tikaConfig);
  6. Metadata metadata = new Metadata();
  7. tika.parse(url.openStream(), metadata);
  8. return metadata;
  9. }
  10. }

代码示例来源:origin: apache/tika

  1. @Test
  2. public void testToString() {
  3. String version = new Tika().toString();
  4. assertNotNull(version);
  5. assertTrue(version.matches(
  6. "Apache Tika \\d+\\.\\d+(\\.\\d+)?(-SNAPSHOT)?"));
  7. }

代码示例来源:origin: apache/tika

  1. @Test
  2. public void testInitializableParser() throws Exception {
  3. URL configFileUrl = getClass().getClassLoader().getResource(TIKA_CFG_FILE);
  4. assert configFileUrl != null;
  5. TikaConfig config = new TikaConfig(configFileUrl);
  6. Tika tika = new Tika(config);
  7. Metadata md = new Metadata();
  8. tika.parse(TikaInputStream.get("someString".getBytes(StandardCharsets.ISO_8859_1)), md);
  9. assertEquals("5", md.get(DummyInitializableParser.SUM_FIELD));
  10. }
  11. }

代码示例来源:origin: apache/tika

  1. @Test
  2. public void testGetVersion() throws Exception {
  3. Response response = WebClient
  4. .create(endPoint + VERSION_PATH)
  5. .type("text/plain")
  6. .accept("text/plain")
  7. .get();
  8. assertEquals(new Tika().toString(),
  9. getStringFromInputStream((InputStream) response.getEntity()));
  10. }
  11. }

相关文章