package name.ixr.webserver; import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; import java.util.Map; import java.util.TreeMap; /** * 全局变量 * @author IXR * */ public class Global { /** WEB目录 */ public static File directory = new File("WebRoot"); /** 服务端口 */ public static int port = 80; /** 线程池 */ public static int pool = 10; /** 服务器编码 */ public static String charset = "UTF-8"; /** 缓冲大小 */ public static int buffer_size = 1024; /** 默认页面 */ public static String[] default_page = {"index.html","index.htm","index.txt"}; /** 文件对应的类型 */ public static Map<String, String> typeMap = new TreeMap<String, String>(); static{ // 加载文件类型映射 try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Global.class.getResourceAsStream("type.txt"))); String line = null; while((line = bufferedReader.readLine()) != null){ String[] typeinfo = line.split(","); typeMap.put(typeinfo[0], typeinfo[1]); } } catch (Exception e) { typeMap.put("html", "text/html"); typeMap.put("htm", "text/html"); } } }