org.apache.tika.mime
Class MimeType

java.lang.Object
  extended by org.apache.tika.mime.MimeType
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MimeType>

public final class MimeType
extends java.lang.Object
implements java.lang.Comparable<MimeType>, java.io.Serializable

Internet media type.

See Also:
Serialized Form

Method Summary
 int compareTo(MimeType mime)
           
 boolean equals(java.lang.Object o)
           
 java.lang.String getDescription()
          Returns the description of this media type.
 java.lang.String getExtension()
          Returns the preferred file extension of this type, or an empty string if no extensions are known.
 java.util.List<java.lang.String> getExtensions()
          Returns the list of all known file extensions of this media type.
 java.lang.String getName()
          Returns the name of this media type.
 MediaType getType()
          Returns the normalized media type name.
 int hashCode()
           
 boolean hasMagic()
           
static boolean isValid(java.lang.String name)
          Checks that the given string is a valid Internet media type name based on rules from RFC 2054 section 5.3.
 boolean matches(byte[] data)
           
 boolean matchesMagic(byte[] data)
           
 void setDescription(java.lang.String description)
          Set the description of this media type.
 java.lang.String toString()
          Returns the name of this media type.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

isValid

public static boolean isValid(java.lang.String name)
Checks that the given string is a valid Internet media type name based on rules from RFC 2054 section 5.3. For validation purposes the rules can be simplified to the following:
 name := token "/" token
 token := 1*<any (US-ASCII) CHAR except SPACE, CTLs, or tspecials>
 tspecials :=  "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" /
               "\" / <"> / "/" / "[" / "]" / "?" / "="
 

Parameters:
name - name string
Returns:
true if the string is a valid media type name, false otherwise

getType

public MediaType getType()
Returns the normalized media type name.

Returns:
media type

getName

public java.lang.String getName()
Returns the name of this media type.

Returns:
media type name (lower case)

getDescription

public java.lang.String getDescription()
Returns the description of this media type.

Returns:
media type description

setDescription

public void setDescription(java.lang.String description)
Set the description of this media type.

Parameters:
description - media type description

hasMagic

public boolean hasMagic()

matchesMagic

public boolean matchesMagic(byte[] data)

matches

public boolean matches(byte[] data)

compareTo

public int compareTo(MimeType mime)
Specified by:
compareTo in interface java.lang.Comparable<MimeType>

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the name of this media type.

Overrides:
toString in class java.lang.Object
Returns:
media type name

getExtension

public java.lang.String getExtension()
Returns the preferred file extension of this type, or an empty string if no extensions are known. Use the getExtensions() method to get the full list of known extensions of this type.

Returns:
preferred file extension or empty string
Since:
Apache Tika 0.9

getExtensions

public java.util.List<java.lang.String> getExtensions()
Returns the list of all known file extensions of this media type.

Returns:
known extensions in order of preference (best first)
Since:
Apache Tika 0.10


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.