📄 protocol.java
字号:
package com.booqio.emulator.io.http;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.microedition.io.HttpConnection;
import a.a.a.midp.io.ConnectionBaseAdapter;
public class Protocol extends ConnectionBaseAdapter implements HttpConnection {
HttpURLConnection instance;
URL url;
InputStream is;
OutputStream os;
public Protocol() {
super();
}
protected void connect(String name, int mode, boolean timeouts)
throws IOException {
url=new URL("http:"+name);
instance=(HttpURLConnection)url.openConnection();
is=null;
os=null;
}
protected void disconnect() throws IOException {
instance.disconnect();
}
protected int readBytes(byte[] b, int off, int len) throws IOException {
// TODO Auto-generated method stub
if(is==null){
is=instance.getInputStream();
}
return is.read(b,off,len);
}
protected int writeBytes(byte[] b, int off, int len) throws IOException {
// TODO Auto-generated method stub
if(os==null){
instance.setDoOutput(true);
os=instance.getOutputStream();
}
os.write(b,off,len);
return len;
}
public String getURL() {
// TODO Auto-generated method stub
return url.getProtocol()+"://"+url.getHost()+":"+url.getPort()+"/"+url.getPath();
}
public String getProtocol() {
// TODO Auto-generated method stub
return "Http";
}
public String getHost() {
// TODO Auto-generated method stub
return url.getHost();
}
public String getFile() {
// TODO Auto-generated method stub
return url.getFile();
}
public String getRef() {
// TODO Auto-generated method stub
return url.getRef();
}
public String getQuery() {
// TODO Auto-generated method stub
return url.getQuery();
}
public int getPort() {
// TODO Auto-generated method stub
return url.getPort();
}
public String getRequestMethod() {
// TODO Auto-generated method stub
return instance.getRequestMethod();
}
public void setRequestMethod(String method) throws IOException {
// TODO Auto-generated method stub
instance.setRequestMethod(method);
}
public String getRequestProperty(String key) {
// TODO Auto-generated method stub
return instance.getRequestProperty(key);
}
public void setRequestProperty(String key, String value) throws IOException {
// TODO Auto-generated method stub
//System.out.println(key+"="+value);
instance.setRequestProperty(key,value);
}
public int getResponseCode() throws IOException {
// TODO Auto-generated method stub
return instance.getResponseCode();
}
public String getResponseMessage() throws IOException {
// TODO Auto-generated method stub
return instance.getResponseMessage();
}
public long getExpiration() throws IOException {
// TODO Auto-generated method stub
return instance.getExpiration();
}
public long getDate() throws IOException {
// TODO Auto-generated method stub
return instance.getDate();
}
public long getLastModified() throws IOException {
// TODO Auto-generated method stub
return instance.getLastModified();
}
public String getHeaderField(String name) throws IOException {
// TODO Auto-generated method stub
return instance.getHeaderField(name);
}
public int getHeaderFieldInt(String name, int def) throws IOException {
// TODO Auto-generated method stub
return instance.getHeaderFieldInt(name,def);
}
public long getHeaderFieldDate(String name, long def) throws IOException {
// TODO Auto-generated method stub
return instance.getHeaderFieldDate(name,def);
}
public String getHeaderField(int n) throws IOException {
// TODO Auto-generated method stub
return instance.getHeaderField(n);
}
public String getHeaderFieldKey(int n) throws IOException {
// TODO Auto-generated method stub
return instance.getHeaderFieldKey(n);
}
public String getEncoding() {
// TODO Auto-generated method stub
return instance.getContentEncoding();
}
public long getLength() {
// TODO Auto-generated method stub
return instance.getContentLength();
}
public String getType() {
// TODO Auto-generated method stub
return instance.getContentType();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -