httpversion.java
来自「RFC 1945 Http1.0协议实现。对协议进行了完整面向对象设计」· Java 代码 · 共 83 行
JAVA
83 行
/**
*
*/
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 + =
减小字号Ctrl + -
显示快捷键?