Codota Logo
Tika.<init>
Code IndexAdd Codota to your IDE (free)

How to use
org.apache.tika.Tika
constructor

Best Java code snippets using org.apache.tika.Tika.<init> (Showing top 20 results out of 414)

  • Common ways to obtain Tika
private void myMethod () {
Tika t =
  • Codota Iconnew Tika()
  • Codota IconTikaConfig config;new Tika(config)
  • Smart code suggestions by Codota
}
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()));
  }
}
org.apache.tikaTika<init>

Javadoc

Creates a Tika facade using the default configuration.

Popular methods of Tika

  • detect
    Detects the media type of the given document. The type detection is based on the first few bytes of
  • parseToString
    Parses the file at the given path and returns the extracted text content. To avoid unpredictable exc
  • parse
    Parses the file at the given path and returns the extracted text content. Metadata information extr
  • toString
  • getParser
    Returns the parser instance used by this facade.
  • setMaxStringLength
    Sets the maximum length of strings returned by the parseToString methods.

Popular in Java

  • Reading from database using SQL prepared statement
  • setRequestProperty (URLConnection)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • HashSet (java.util)
    This class implements the Set interface, backed by a hash table (actually a HashMap instance). It m
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now