ccs.mime
Class MimeType

java.lang.Object
  extended by ccs.mime.MimeType
All Implemented Interfaces:
java.lang.Comparable<MimeType>

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

A MimeType encapsulates available information about a specified MIME type. MimeType objects are usually managed and obtained from a MimeRegistry. Once created, the MIME type string is invariant, but the auxiliary information may be changed.


Field Summary
static java.lang.String APPOCT
          The application/octet-stream type.
static int MAYBE
          Objects of this MIME type may or may not be compressable.
static int NO
          Objects of this MIME type may not usefully be compressed by Zip using Zip or similar algorithms.
static int YES
          Objects of this MIME type may be usefully compressed using Zip or similar algorithms.
 
Constructor Summary
MimeType(java.lang.String type, java.lang.String[] extns, int compressibility, java.lang.String description)
          Build a MimeType.
 
Method Summary
 int compareTo(MimeType mt)
           
 boolean equals(java.lang.Object o)
           
 int getCompressibility()
          Returns the compressibility of this type.
 java.lang.String getDescription()
          Get the description.
 java.lang.String[] getExtensions()
          Returns the array of extensions that indciate this MIME type.
 java.lang.String getType()
          The MIME type string.
 void setCompressibility(int compressibility)
          Sets the compressibility of this type.
 void setDescription(java.lang.String description)
          Sets the description
 void xmlMarshal(CXTStream cxt)
          Marshal the MimeType as XML.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPOCT

public static final java.lang.String APPOCT
The application/octet-stream type. This is used as a fallback for files which don't have any recognised type of their own.

See Also:
Constant Field Values

YES

public static final int YES
Objects of this MIME type may be usefully compressed using Zip or similar algorithms.

See Also:
Constant Field Values

NO

public static final int NO
Objects of this MIME type may not usefully be compressed by Zip using Zip or similar algorithms. Typically these types are compressed internally.

See Also:
Constant Field Values

MAYBE

public static final int MAYBE
Objects of this MIME type may or may not be compressable. Either we don't know or the format has subtypes of differing compressibility. YMMV!

See Also:
Constant Field Values
Constructor Detail

MimeType

public MimeType(java.lang.String type,
                java.lang.String[] extns,
                int compressibility,
                java.lang.String description)
Build a MimeType.

Parameters:
type - The MIME type string. This should follow the usual MIME type/subtype format: e.g. "text/plain", "text/html", "audio/wav" etc. Custom types - those that either you've invented yourself, or which are more standard but have not been approved by the IANA - should be prefixed with "x-": e.g. "application/x-myapp-control-data" or even "x-myapp/x-control-data-stream". "application/octet-stream" is a catchall, signifying an opaque binary which is not recognised as being in any known format. For more information see RFC2046.
extns - A list of filename extensions that correspond to the MIME type. Given some file and no a exteriori metainformation, there are two main ways to work out the most likely MIME type for the content. The first way is to look for some identifying header - "magic" - in the file itself. This requires the classifying app to have detailed knowledge of all the formats which it's supposed to deal in; this is not appropriate for a transport-type app, in the case of propriatary formats this information is unavailable, and some types do not have a standard header. The easier and more common (although somewhat less reliable) method is based on the filename "extension", defined as anything in the filename after the last instance of a "." character. This is a generalisation to UNIX of an idea from VMS, via CP/M and hence DOS. These extensions include the preceding ".", such that java expressions of the form filename.endsWith(extn[i]) will give the right answer. Historically, extensions were required to have 3 characters and many have stuck with this, but it's no longer necessary: e.g. ".html" is the standard, not ".htm".
compressibility - Whether attempting to compress streams in this format using a general-purpose compression algorithm is useful. Compressing text streams is generally useful in reducing bandwith and increasing cryptosecurity (sparse plaintext can make cryptanalysis easier). Trying to compress video streams that are highly compressed internally will usually make the stream bigger. Allowed values are YES, NO and MAYBE, defined above.
description - A user-friendly, one-line description of the type.
Method Detail

getType

public java.lang.String getType()
The MIME type string. This is immutable, hence the lack of a setter method.

Returns:
The type string.

getExtensions

public java.lang.String[] getExtensions()
Returns the array of extensions that indciate this MIME type. NB. This returns the actual array, not a copy. Callers contract not to change the array; if they break this contract, the changes will not be reflected in any MimeRegistry of which this is a member, to their sorrow. To change the list of extensions, callers must remove the entry from the MimeRegistry and replace it with an updated one.

Returns:
The array of strings indicating the available extensions.

getCompressibility

public int getCompressibility()
Returns the compressibility of this type.

Returns:
One of the constants YES, NO or MAYBE.

setCompressibility

public void setCompressibility(int compressibility)
Sets the compressibility of this type.

Parameters:
compressibility - One of the constants YES, NO or MAYBE.

getDescription

public java.lang.String getDescription()
Get the description.

Returns:
The description.

setDescription

public void setDescription(java.lang.String description)
Sets the description

Parameters:
description - The new description.

xmlMarshal

public void xmlMarshal(CXTStream cxt)
                throws java.io.IOException
Marshal the MimeType as XML.

Parameters:
cxt - The stream to marshal to
Throws:
java.io.IOException - If thrown by the stream.

compareTo

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

equals

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