⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpservice.java

📁 RFC 1945 Http1.0协议实现。对协议进行了完整面向对象设计
💻 JAVA
字号:
/**
 * 
 */
package edu.sysu.http.util;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

import edu.sysu.http.intf.HttpHandler;

/**
 * @author Administrator
 * 
 */
public class HttpService {
	/*
	 * member of command files
	 */
	private File cmdPath;
	private File classPath;

	/*
	 * constructor
	 */
	private HttpService() {
		//File f = new File(".");
		String path = new String();
		//path = f.getCanonicalPath();
		path = System.getProperty("user.dir");
		this.cmdPath = new File(path + "\\bin\\edu\\sysu\\http\\impl");
		this.classPath = new File(path + "\\bin");
		// this.cmdPath = new File(path);
	}

	/*
	 * load in all commands of agenda application
	 */
	public HttpHandler loadMethodClass(String file)
			throws HttpResourceException {
		String[] files = this.cmdPath.list(new FileFilter(file));
		if (files != null && files.length == 1) {
			String tmp = ParseInput.getInstance().trimExtension(files[0]);
			try {
				URL url = this.cmdPath.toURI().toURL();
				// initialize url class loader
				ClassLoader loader = new URLClassLoader(new URL[] { url });
				Class<?> cls = loader.loadClass("edu.sysu.http.impl." + tmp);
				Object obj = cls.newInstance();
				return (HttpHandler) obj;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				throw new HttpResourceException("Creating instance invalid.");
			}
		} else {
			try {
				System.out.println(this.cmdPath.toURI().toURL().toString());
			} catch (MalformedURLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new HttpResourceException("Class file invalid");
		}
	}

	/**
	 * static class for Singleton design pattern, instance of HttpService will
	 * be created when the first time you make a call to HttpService.getInstance
	 * 
	 * @author Cyberpet
	 * @see HttpService#getInstance()
	 */
	static class HttpServiceSingletonHolder {
		static HttpService instance = new HttpService();
	}

	/**
	 * get the only instance of HttpService
	 * 
	 * @return HttpService
	 * @see HttpService
	 */
	public static HttpService getInstance() {
		return HttpServiceSingletonHolder.instance;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -