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

📄 httpversion.java

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

import edu.sysu.http.util.HttpGrammarException;
import edu.sysu.http.util.HttpRegex;

/**
 * @author Administrator
 * 
 *         HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
 * 
 */
public class HttpVersion {

	private String version = "0.9";
	private String HTTP = "HTTP";
	private String backlash = "/";
	private HttpRegex regex = new HttpRegex();

	public HttpRegex getRegex() {
		return regex;
	}

	public void setRegex(HttpRegex regex) {
		this.regex = regex;
	}

	public HttpVersion() {
		this.regex.SetPattern("^" + this.HTTP + this.backlash + HttpRules.DIGIT
				+ "+\\." + HttpRules.DIGIT + "+");
	}

	public HttpVersion(String version) throws HttpGrammarException{
		this();
		this.setVersion(version);
	}

	public String toString() {
		return this.HTTP + this.backlash + this.version;
	}

	public void setVersion(String version) throws HttpGrammarException {
		if (this.regex.Match(this.HTTP + this.backlash + version))
			this.version = version;
		else
			throw new HttpGrammarException("Http-Version invalid.");
	}

	public String getVersion() {
		return version;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		HttpVersion ver;
		try {
			ver = new HttpVersion("1.1");
			System.out.println(ver.toString());
		} catch (HttpGrammarException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		HttpVersion ver1;
		try {
			ver1 = new HttpVersion("a.1");
			System.out.println(ver1.toString());
		} catch (HttpGrammarException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

⌨️ 快捷键说明

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