I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Unverified Commit 04dd1861 authored by zzz's avatar zzz
Browse files

i2psnark: Load sytem mime types if available

parent 265f5ee5
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,10 @@
package org.klomp.snark.web;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
......@@ -21,6 +25,9 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import net.i2p.data.DataHelper;
import net.i2p.util.SystemVersion;
/* ------------------------------------------------------------ */
/**
......@@ -47,6 +54,8 @@ class MimeTypes
public MimeTypes() {
_mimeMap = new ConcurrentHashMap<String, String>();
if (!(SystemVersion.isWindows() || SystemVersion.isMac() || SystemVersion.getMaxMemory() < 100*1024*1024L))
loadSystemMimeTypes();
}
/* ------------------------------------------------------------ */
......@@ -86,6 +95,37 @@ class MimeTypes
}
}
/**
* Load mime types from /etc/mime.types
* Format: mimetype suffix1 suffix2 ...
*
* @since 0.9.54
*/
private void loadSystemMimeTypes() {
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream("/etc/mime.types"), "ISO-8859-1"));
while (true) {
String line = in.readLine();
if (line == null)
break;
if (line.startsWith("#"))
continue;
String[] s = DataHelper.split(line, "[ \t]+", 16);
if (s.length < 2)
continue;
for (int i = 1; i < s.length; i++) {
_mimeMap.put(s[i].toLowerCase(Locale.US), s[0]);
//System.out.println("Mapping: '" + s[i] + "' -> '" + s[0] + "'");
}
}
//System.out.println("Loaded " + _mimeMap.size() + " mime types from /etc/mime.types");
} catch (IOException ioe) {
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
}
}
/* ------------------------------------------------------------ */
/** Get the MIME type by filename extension.
*
......
......@@ -90,6 +90,9 @@
@{PROC}/sys/net/ipv6/conf/all/temp_valid_lft r,
@{PROC}/sys/net/ipv6/conf/all/use_tempaddr r,
# i2psnark
/etc/mime.types r,
# 'm' is needed by the I2P-Bote plugin
/{,lib/live/mount/overlay/}tmp/ rwm,
owner /{,lib/live/mount/overlay/}tmp/hsperfdata_*/ rwk,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment