1 public class Query extends Socket {
7 private String hostname;
10 private StringBuffer response;
12 public Query(String hostname, String path) {
13 this.hostname=hostname;
15 response=new StringBuffer();
19 public void makeConnection() {
20 InetAddress address=InetAddress.getByName(hostname);
22 fd=nativeBind(address.getAddress(), port);
23 nativeConnect(fd, address.getAddress(), port);
26 public String getHostName() {
30 public String getPath() {
34 public void outputFile() {
35 StringBuffer sb=new StringBuffer(hostname);
37 FileOutputStream fos=new FileOutputStream(sb.toString().replace('/','#'));
38 fos.write(response.toString().getBytes());
42 public String makewebcanonical(String page) {
43 StringBuffer b=new StringBuffer(getHostName(page));
45 b.append(getPathName(page));
49 public String getHostName(String page) {
50 String http=new String("http://");
51 if (page.indexOf(http)==-1) {
54 int beginindex=page.indexOf(http)+http.length();
55 int endindex=page.indexOf('/',beginindex+1);
56 if ((beginindex==-1)) {
57 System.printString("ERROR");
60 endindex=page.length();
61 return page.subString(beginindex, endindex);
65 public String getPathName(String page) {
66 String http=new String("http://");
67 if (page.indexOf(http)==-1) {
68 String path=getPath();
69 int lastindex=path.lastindexOf('/');
73 StringBuffer sb=new StringBuffer(path.subString(0,lastindex+1));
77 int beginindex=page.indexOf(http)+http.length();
78 int nextindex=page.indexOf('/',beginindex+1);
79 if ((beginindex==-1)||(nextindex==-1))
80 return new String("index.html");
81 return page.subString(nextindex+1, page.length()-1);