org.apache.tika.mime
Class MimeType

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

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

Internet media type.


Method Summary
 void addAlias(java.lang.String alias)
          Adds an alias name for this media type.
 int compareTo(MimeType type)
           
 java.lang.String getDescription()
          Returns the description of this media type.
 java.lang.String getName()
          Returns the name of this media type.
 MimeType getSuperType()
          Returns the parent of this media type.
 boolean hasMagic()
           
 boolean isDescendantOf(MimeType type)
           
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.
 void setSuperType(MimeType type)
           
 java.lang.String toString()
          Returns the name of this media type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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

getName

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

Returns:
media type name (lower case)

getSuperType

public MimeType getSuperType()
Returns the parent of this media type.

Returns:
parent media type, or null

setSuperType

public void setSuperType(MimeType type)
                  throws MimeTypeException
Throws:
MimeTypeException

isDescendantOf

public boolean isDescendantOf(MimeType type)

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

addAlias

public void addAlias(java.lang.String alias)
              throws MimeTypeException
Adds an alias name for this media type.

Parameters:
alias - media type alias (case insensitive)
Throws:
MimeTypeException - if the alias is invalid or already registered for another media type

hasMagic

public boolean hasMagic()

matchesMagic

public boolean matchesMagic(byte[] data)

matches

public boolean matches(byte[] data)

compareTo

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

toString

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

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


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