org.apache.tika
Class Tika

java.lang.Object
  extended by org.apache.tika.Tika

public class Tika
extends java.lang.Object

Facade class for accessing Tika functionality. This class hides much of the underlying complexity of the lower level Tika classes and provides simple methods for many common parsing and type detection operations.

Since:
Apache Tika 0.5
See Also:
Parser, Detector

Constructor Summary
Tika()
          Creates a Tika facade using the default configuration.
Tika(TikaConfig config)
          Creates a Tika facade using the given configuration.
 
Method Summary
 java.lang.String detect(java.io.File file)
          Detects the media type of the given file.
 java.lang.String detect(java.io.InputStream stream)
          Detects the media type of the given document.
 java.lang.String detect(java.io.InputStream stream, Metadata metadata)
          Detects the media type of the given document.
 java.lang.String detect(java.lang.String name)
          Detects the media type of a document with the given file name.
 java.lang.String detect(java.net.URL url)
          Detects the media type of the resource at the given URL.
 java.io.Reader parse(java.io.File file)
          Parses the given file and returns the extracted text content.
 java.io.Reader parse(java.io.InputStream stream)
          Parses the given document and returns the extracted text content.
 java.io.Reader parse(java.io.InputStream stream, Metadata metadata)
          Parses the given document and returns the extracted text content.
 java.io.Reader parse(java.net.URL url)
          Parses the resource at the given URL and returns the extracted text content.
 java.lang.String parseToString(java.io.File file)
          Parses the given file and returns the extracted text content.
 java.lang.String parseToString(java.io.InputStream stream)
          Parses the given document and returns the extracted text content.
 java.lang.String parseToString(java.io.InputStream stream, Metadata metadata)
          Parses the given document and returns the extracted text content.
 java.lang.String parseToString(java.net.URL url)
          Parses the resource at the given URL and returns the extracted text content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tika

public Tika(TikaConfig config)
Creates a Tika facade using the given configuration.

Parameters:
config - Tika configuration

Tika

public Tika()
Creates a Tika facade using the default configuration.

Method Detail

detect

public java.lang.String detect(java.io.InputStream stream,
                               Metadata metadata)
                        throws java.io.IOException
Detects the media type of the given document. The type detection is based on the content of the given document stream and any given document metadata. The document stream can be null, in which case only the given document metadata is used for type detection.

If the document stream supports the mark feature, then the stream is marked and reset to the original position before this method returns. Only a limited number of bytes are read from the stream.

The given document stream is not closed by this method.

Unlike in the parse(InputStream, Metadata) method, the given document metadata is not modified by this method.

Parameters:
stream - the document stream, or null
metadata - document metadata
Returns:
detected media type
Throws:
java.io.IOException - if the stream can not be read

detect

public java.lang.String detect(java.io.InputStream stream)
                        throws java.io.IOException
Detects the media type of the given document. The type detection is based on the content of the given document stream.

If the document stream supports the mark feature, then the stream is marked and reset to the original position before this method returns. Only a limited number of bytes are read from the stream.

The given document stream is not closed by this method.

Parameters:
stream - the document stream
Returns:
detected media type
Throws:
java.io.IOException - if the stream can not be read

detect

public java.lang.String detect(java.io.File file)
                        throws java.io.FileNotFoundException,
                               java.io.IOException
Detects the media type of the given file. The type detection is based on the document content and a potential known file extension.

Use the detect(String) method when you want to detect the type of the document without actually accessing the file.

Parameters:
file - the file
Returns:
detected media type
Throws:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException - if the file can not be read

detect

public java.lang.String detect(java.net.URL url)
                        throws java.io.IOException
Detects the media type of the resource at the given URL. The type detection is based on the document content and a potential known file extension included in the URL.

Use the detect(String) method when you want to detect the type of the document without actually accessing the URL.

Parameters:
url - the URL of the resource
Returns:
detected media type
Throws:
java.io.IOException - if the resource can not be read

detect

public java.lang.String detect(java.lang.String name)
Detects the media type of a document with the given file name. The type detection is based on known file name extensions.

The given name can also be a URL or a full file path. In such cases only the file name part of the string is used for type detection.

Parameters:
name - the file name of the document
Returns:
detected media type

parse

public java.io.Reader parse(java.io.InputStream stream,
                            Metadata metadata)
                     throws java.io.IOException
Parses the given document and returns the extracted text content. Input metadata like a file name or a content type hint can be passed in the given metadata instance. Metadata information extracted from the document is returned in that same metadata instance.

Parameters:
stream - the document to be parsed
Returns:
extracted text content
Throws:
java.io.IOException - if the document can not be read or parsed

parse

public java.io.Reader parse(java.io.InputStream stream)
                     throws java.io.IOException
Parses the given document and returns the extracted text content.

Parameters:
stream - the document to be parsed
Returns:
extracted text content
Throws:
java.io.IOException - if the document can not be read or parsed

parse

public java.io.Reader parse(java.io.File file)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Parses the given file and returns the extracted text content.

Parameters:
file - the file to be parsed
Returns:
extracted text content
Throws:
java.io.FileNotFoundException - if the given file does not exist
java.io.IOException - if the file can not be read or parsed

parse

public java.io.Reader parse(java.net.URL url)
                     throws java.io.IOException
Parses the resource at the given URL and returns the extracted text content.

Parameters:
url - the URL of the resource to be parsed
Returns:
extracted text content
Throws:
java.io.IOException - if the resource can not be read or parsed

parseToString

public java.lang.String parseToString(java.io.InputStream stream,
                                      Metadata metadata)
                               throws java.io.IOException,
                                      TikaException
Parses the given document and returns the extracted text content. The given input stream is closed by this method.

Parameters:
stream - the document to be parsed
metadata - document metadata
Returns:
extracted text content
Throws:
java.io.IOException - if the document can not be read
TikaException - if the document can not be parsed

parseToString

public java.lang.String parseToString(java.io.InputStream stream)
                               throws java.io.IOException,
                                      TikaException
Parses the given document and returns the extracted text content. The given input stream is closed by this method.

Parameters:
stream - the document to be parsed
Returns:
extracted text content
Throws:
java.io.IOException - if the document can not be read
TikaException - if the document can not be parsed

parseToString

public java.lang.String parseToString(java.io.File file)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException,
                                      TikaException
Parses the given file and returns the extracted text content.

Parameters:
file - the file to be parsed
Returns:
extracted text content
Throws:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException - if the file can not be read
TikaException - if the file can not be parsed

parseToString

public java.lang.String parseToString(java.net.URL url)
                               throws java.io.IOException,
                                      TikaException
Parses the resource at the given URL and returns the extracted text content.

Parameters:
url - the URL of the resource to be parsed
Returns:
extracted text content
Throws:
java.io.IOException - if the resource can not be read
TikaException - if the resource can not be parsed


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.