SimpleWebServer继承于NanoHTTPD
启动的时候,首先初始化index文件
public static final List<String> INDEX_FILE_NAMES = new ArrayList<String>() {
{
add("index.html");
add("index.htm");
}
};
初始化 mimeType和LICENCE
public static Map<String, String> mimeTypes() {
if (MIME_TYPES == null) {
MIME_TYPES = new HashMap<String, String>();
loadMimeTypes(MIME_TYPES, "META-INF/nanohttpd/default-mimetypes.properties");
loadMimeTypes(MIME_TYPES, "META-INF/nanohttpd/mimetypes.properties");
if (MIME_TYPES.isEmpty()) {
LOG.log(Level.WARNING, "no mime types found in the classpath! please provide mimetypes.properties");
}
}
return MIME_TYPES;
}
看一下这个文件default-mimetypes.properties
然后进入main函数
/**
* Starts as a standalone file server and waits for Enter.
*/
public static void main(String[] args) {
// Defaults
int port = 8080;//端口号
String host = null; // bind to all interfaces by default
List<File> rootDirs = new ArrayList<File>();
boolean quiet = false;
String cors = null;
Map<String, String> options = new HashMap<String, String>();
// Parse command-line, with short and long versions of the options.
for (int i = 0; i < args.length; ++i) {//解析命令行参数
if ("-h".equ