1 public class QueryThread extends Thread {
4 public QueryThread(QueryQueue qq, QueryList ql) {
13 q=toprocess.getQuery();
17 String hostname=q.getHostName();
18 System.printString("Processing ");
19 System.printString(hostname);
20 System.printString(" ");
21 System.printString(q.getPath());
22 System.printString("\n");
23 Socket s=new Socket(hostname, 80);
32 void requestQuery(Query q, Socket sock) {
33 StringBuffer req=new StringBuffer("GET ");
35 req.append(q.getPath());
36 req.append(" HTTP/1.1\r\nHost:");
37 req.append(q.getHostName());
38 req.append("\r\n\r\n");
39 sock.write(req.toString().getBytes());
42 void readResponse(Query q, Socket sock) {
53 int numchars=sock.read(b);
60 } else if (state==1) {
62 int numchars=sock.read(b);
69 } else if (state==2) {
71 int numchars=sock.read(b);
78 } else if (state==3) {
80 int numchars=sock.read(b);
89 byte[] buffer=new byte[1024];
90 int numchars=sock.read(buffer);
94 String curr=(new String(buffer)).subString(0,numchars);
95 q.response.append(curr);
101 void processPage(Query q, QueryList ql) {
103 String href=new String("href=\"");
104 String searchstr=q.response.toString();
107 int mindex=searchstr.indexOf(href,index);
110 int endquote=searchstr.indexOf('"', mindex+href.length());
112 String match=searchstr.subString(mindex+href.length(), endquote);
113 String match2=q.makewebcanonical(match);
114 if (match2!=null&&!ql.checkQuery(match2)) {
116 System.printString(q.getHostName(match));
117 System.printString(" ");
118 System.printString(q.getPathName(match));
119 System.printString("\n");
120 Query newq=new Query(q.getHostName(match), q.getPathName(match));
121 toprocess.addQuery(newq);