httptype.java

来自「RFC 1945 Http1.0协议实现。对协议进行了完整面向对象设计」· Java 代码 · 共 71 行

JAVA
71
字号
/**
 * 
 */
package edu.sysu.http.impl;

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

/**
 * @author Administrator
 * 
 */
public class HttpType {

	private String type;
	private String subtype;
	private HttpRegex regex = new HttpRegex();

	/**
	 * 
	 */
	public HttpType() {
		// TODO Auto-generated constructor stub
		this.regex.SetPattern(".+");
	}

	public HttpType(String type, String subtype) throws HttpGrammarException {
		this();
		this.setType(type);
		this.setSubtype(subtype);
	}

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

	}

	public void setType(String type) throws HttpGrammarException {
		if (this.regex.Match(type))
			this.type = type;
		else
			throw new HttpGrammarException("Type invalid.");
	}

	public String getType() {
		return type;
	}

	public void setSubtype(String subtype) throws HttpGrammarException {
		if (this.regex.Match(subtype))
			this.subtype = subtype;
		else
			throw new HttpGrammarException("SubType invalid.");
	}

	public String getSubtype() {
		return subtype;
	}

	public String toString() {
		if(this.type != null && this.subtype != null)
			return this.type + "/" + this.subtype;
		else
			return null;
	}

}

⌨️ 快捷键说明

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