Map<String, String> map = new HashMap<String, String>();
mimeTypeMap = Collections.unmodifiableMap(map);
InputStreamReader isr = null;
LineNumberReader lnr = null;
try {
isr = new InputStreamReader(HttpUtils.class.getResourceAsStream("/org/xlightweb/mime.types"));
if (isr != null) {
lnr = new LineNumberReader(isr);
String line = null;
while (true) {
line = lnr.readLine();
if (line != null) {
line = line.trim();
if (!line.startsWith("#")) {
StringTokenizer st = new StringTokenizer(line);
if (st.hasMoreTokens()) {
String mimeType = st.nextToken();
while (st.hasMoreTokens()) {
String extension = st.nextToken();
map.put(extension, mimeType);
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("mapping " + extension + " -> " + mimeType + " added");
}
}
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("line " + line + "ignored");
}
}
}
} else {
break;
}
}
lnr.close();
}
} catch (Exception ioe) {
// eat and log exception
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("could not read mime.types. reason: " + ioe.toString());
}
} finally {
try {
if (lnr != null) {
lnr.close();
}
if (isr != null) {
isr.close();
}