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

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

本文整理了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

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

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

protected void getMimeType(InputStream inputStream, String fileName, StaticAsset newAsset) {
  Tika tika = new Tika();
  String tikaMimeType = tika.detect(fileName);
  if (tikaMimeType == null) {
    try {
      tikaMimeType = tika.detect(inputStream);
    } catch (IOException e) {
      //if tika can't resolve, don't throw exception
    }
  }
  if (tikaMimeType != null) {
    newAsset.setMimeType(tikaMimeType);
  }
}

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

public static void main(String[] args) throws Exception {
    // Create a Tika instance with the default configuration
    Tika tika = new Tika();

    // Parse all given files and print out the extracted
    // text content
    for (String file : args) {
      String text = tika.parseToString(new File(file));
      System.out.print(text);
    }
  }
}

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

public static void main(String[] args) throws Exception {
    Tika tika = new Tika();

    for (String file : args) {
      String type = tika.detect(new File(file));
      System.out.println(file + ": " + type);
    }
  }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

public AgeRecogniser() {
  try {
    secondaryParser = new Tika(new TikaConfig());
    available = true;
  } catch (Exception e) {
    available = false;
    LOG.log(Level.SEVERE, "Unable to initialize secondary parser");
  }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@Test
  public void testGetVersion() throws Exception {
    Response response = WebClient
        .create(endPoint + VERSION_PATH)
        .type("text/plain")
        .accept("text/plain")
        .get();

    assertEquals(new Tika().toString(),
        getStringFromInputStream((InputStream) response.getEntity()));
  }
}

相关文章