|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tika.mime.MimeTypes
public final class MimeTypes
This class is a MimeType repository. It gathers a set of MimeTypes and enables to retrieves a content-type from its name, from a file name, or from a magic character sequence.
The MIME type detection methods that take an InputStream
as
an argument will never reads more than getMinLength()
bytes
from the stream. Also the given stream is never
closed
, marked
,
or reset
by the methods. Thus a client can
use the mark feature
of the stream
(if available) to restore the stream back to the state it was before type
detection if it wants to process the stream based on the detected type.
Field Summary | |
---|---|
static java.lang.String |
OCTET_STREAM
Name of the root type, application/octet-stream. |
static java.lang.String |
PLAIN_TEXT
Name of the text type, text/plain. |
static java.lang.String |
XML
Name of the xml type, application/xml. |
Constructor Summary | |
---|---|
MimeTypes()
|
Method Summary | |
---|---|
void |
addPattern(MimeType type,
java.lang.String pattern)
Adds a file name pattern for the given media type. |
void |
addPattern(MimeType type,
java.lang.String pattern,
boolean isRegex)
Adds a file name pattern for the given media type. |
MediaType |
detect(java.io.InputStream input,
Metadata metadata)
Automatically detects the MIME type of a document based on magic markers in the stream prefix and any given metadata hints. |
MimeType |
forName(java.lang.String name)
Returns the registered media type with the given name (or alias). |
static MimeTypes |
getDefaultMimeTypes()
Get the default MimeTypes |
MediaTypeRegistry |
getMediaTypeRegistry()
|
MimeType |
getMimeType(byte[] data)
Deprecated. Use the Tika.detect(byte[]) method |
MimeType |
getMimeType(java.io.File file)
Deprecated. Use the Tika.detect(File) method |
MimeType |
getMimeType(java.io.InputStream stream)
Deprecated. Use the Tika.detect(InputStream) method |
MimeType |
getMimeType(java.lang.String name)
Deprecated. Use the Tika.detect(String) method |
MimeType |
getMimeType(java.lang.String name,
byte[] data)
Deprecated. Use the Tika.detect(byte[], String) method |
MimeType |
getMimeType(java.lang.String name,
java.io.InputStream stream)
Deprecated. Use the Tika.detect(InputStream,String) method |
MimeType |
getMimeType(java.net.URL url)
Deprecated. Use the Tika.detect(URL) method |
int |
getMinLength()
Return the minimum length of data to provide to analyzing methods based on the document's content in order to check all the known MimeTypes. |
java.lang.String |
getType(java.lang.String typeName,
java.lang.String url,
byte[] data)
Deprecated. Use the Tika#detect(InputStream, Metadata)) method |
java.lang.String |
getType(java.net.URL url)
Deprecated. Use the Tika.detect(URL) method |
void |
setSuperType(MimeType type,
MediaType parent)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String OCTET_STREAM
root
type, application/octet-stream.
public static final java.lang.String PLAIN_TEXT
text
type, text/plain.
public static final java.lang.String XML
xml
type, application/xml.
Constructor Detail |
---|
public MimeTypes()
Method Detail |
---|
public MimeType getMimeType(java.io.File file)
Tika.detect(File)
method
file
- to analyze.
null
if none is found.public MimeType getMimeType(java.net.URL url)
Tika.detect(URL)
method
url
- of the document to analyze.
null
if none is found.public MimeType getMimeType(java.lang.String name)
Tika.detect(String)
method
name
- of the document to analyze.
public MimeType getMimeType(byte[] data)
Tika.detect(byte[])
method
The given byte array is expected to be at least getMinLength()
long, or shorter only if the document stream itself is shorter.
data
- first few bytes of a document stream
public MimeType getMimeType(java.io.InputStream stream) throws java.io.IOException
Tika.detect(InputStream)
method
stream
- document stream
null
if no match is found
java.io.IOException
- if the stream can be readpublic java.lang.String getType(java.lang.String typeName, java.lang.String url, byte[] data)
Tika#detect(InputStream, Metadata))
method
public java.lang.String getType(java.net.URL url) throws java.io.IOException
Tika.detect(URL)
method
url
- URL of the document
java.io.IOException
- if the document can not be accessedpublic MimeType getMimeType(java.lang.String name, byte[] data)
Tika.detect(byte[], String)
method
name
- of the document to analyze.data
- are the first bytes of the document's content.
null
if none is found.getMinLength()
public MimeType getMimeType(java.lang.String name, java.io.InputStream stream) throws java.io.IOException
Tika.detect(InputStream,String)
method
name
- document namestream
- document stream
null
if no match is found
java.io.IOException
- if the stream can not be readgetMimeType(String, byte[])
public MimeType forName(java.lang.String name) throws MimeTypeException
name
- media type name (case-insensitive)
MimeTypeException
- if the given media type name is invalidpublic void setSuperType(MimeType type, MediaType parent)
public void addPattern(MimeType type, java.lang.String pattern) throws MimeTypeException
type
- media typepattern
- file name pattern
MimeTypeException
- if the pattern conflicts with existing onespublic void addPattern(MimeType type, java.lang.String pattern, boolean isRegex) throws MimeTypeException
isRegex
parameter. If the value
is set to true, then a JDK standard regex is assumed, otherwise the
freedesktop glob type is assumed.
type
- media typepattern
- file name patternisRegex
- set to true if JDK std regexs are desired, otherwise set to
false.
MimeTypeException
- if the pattern conflicts with existing ones.public MediaTypeRegistry getMediaTypeRegistry()
public int getMinLength()
getMimeType(byte[])
,
getMimeType(String, byte[])
public MediaType detect(java.io.InputStream input, Metadata metadata) throws java.io.IOException
The given stream is expected to support marks, so that this method can reset the stream to the position it was in before this method was called.
detect
in interface Detector
input
- document stream, or null
metadata
- metadata hints
java.io.IOException
- if the document stream could not be readpublic static MimeTypes getDefaultMimeTypes()
MimeTypeException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |