-/* taken from freenet (http://www.freenetproject.org/) */
+/* taken from freenet (http://www.freenetproject.org/) */
package de.todesbaum.util.mime;
import java.util.HashMap;
* Holds the default MIME types.
*/
public class DefaultMIMETypes {
-
+
/** Default MIME type - what to set it to if we don't know any better */
public static final String DEFAULT_MIME_TYPE = "application/octet-stream";
-
+
/** MIME types: number -> name */
private static List<String> mimeTypesByNumber = new Vector<String>();
-
+
/** MIME types: name -> number */
private static Map<String, Short> mimeTypesByName = new HashMap<String, Short>();
-
+
/** MIME types by extension. One extension maps to one MIME type, but not necessarily
* the other way around. */
private static Map<String, Short> mimeTypesByExtension = new HashMap<String, Short>();
-
+
/** Primary extension by MIME type number. */
private static Map<Short, String> primaryExtensionByMimeNumber = new HashMap<Short, String>();
-
+
/**
* Add a MIME type, without any extensions.
* @param number The number of the MIME type for compression. This *must not change*
}
if(outExtension != null)
primaryExtensionByMimeNumber.put(t, outExtension);
-
+
}
/**
protected static synchronized void addMIMEType(short number, String type, String extensions, String outExtension) {
addMIMEType(number, type, extensions.split(" "), outExtension);
}
-
+
/**
* Get a known MIME type by number.
*/
return null;
return mimeTypesByNumber.get(x);
}
-
+
/**
* Get the number of a MIME type, or -1 if it is not in the table of known MIME
* types, in which case it will have to be sent uncompressed.
if(x != null) return x.shortValue();
return -1;
}
-
+
/* From toad's /etc/mime.types
- * cat /etc/mime.types | sed "/^$/d;/#/d" | tr --squeeze '\t' ' ' |
- * (y=0; while read x; do echo "$x" |
+ * cat /etc/mime.types | sed "/^$/d;/#/d" | tr --squeeze '\t' ' ' |
+ * (y=0; while read x; do echo "$x" |
* sed -n "s/^\([^ ]*\)$/addMIMEType\($y, \"\1\"\);/p;s/^\([^ (),]\+\) \(.*\)$/addMIMEType\($y, \"\1\", \"\2\"\);/p;"; y=$((y+1)); done)
*/
-
+
static {
addMIMEType((short) 0, "application/activemessage");
addMIMEType((short) 1, "application/andrew-inset", "ez");
addMIMEType((short) 686, "x-conference/x-cooltalk", "ice");
addMIMEType((short) 687, "x-world/x-vrml", "vrm vrml wrl");
}
-
+
/** Guess a MIME type from a filename */
public static String guessMIMEType(String arg) {
int x = arg.lastIndexOf('.');
if(typeNumber < 0) return null;
return primaryExtensionByMimeNumber.get(typeNumber);
}
-
+
public static String[] getAllMIMETypes() {
return mimeTypesByNumber.toArray(new String[mimeTypesByNumber.size()]);
}