private String hostname;
private String path;
- private Socket connection;
private StringBuffer response;
public Query(String hostname, String path) {
nativeConnect(fd, address.getAddress(), port);
}
- public void setSocket(Socket s) {
- connection=s;
- }
-
public String getHostName() {
return hostname;
}
public String getPath() {
return path;
}
+
+ public void outputFile() {
+ StringBuffer sb=new StringBuffer(hostname);
+ sb.append(path);
+ FileOutputStream fos=new FileOutputStream(sb.toString().replace('/','#'));
+ fos.write(response.toString().getBytes());
+ fos.close();
+ }
public String makewebcanonical(String page) {
StringBuffer b=new StringBuffer(getHostName(page));
} else {
int beginindex=page.indexOf(http)+http.length();
int endindex=page.indexOf('/',beginindex+1);
- if ((beginindex==-1)||(endindex==-1))
+ if ((beginindex==-1)) {
System.printString("ERROR");
+ }
+ if (endindex==-1)
+ endindex=page.length();
return page.subString(beginindex, endindex);
}
}
int beginindex=page.indexOf(http)+http.length();
int nextindex=page.indexOf('/',beginindex+1);
if ((beginindex==-1)||(nextindex==-1))
- System.printString("ERROR");
+ return new String("index.html");
return page.subString(nextindex+1, page.length()-1);
}
}
int numchars=q.read(b);
if ((numchars==1) && (b[0]=='\r'))
q.state++;
- System.printString(new String(b));
} else if (q.state==1) {
byte[] b=new byte[1];
int numchars=q.read(b);
q.state++;
else
q.state=0;
- System.printString(new String(b));
}
} else if (q.state==2) {
byte[] b=new byte[1];
q.state++;
else
q.state=0;
- System.printString(new String(b));
}
} else if (q.state==3) {
byte[] b=new byte[1];
q.state++;
else
q.state=0;
- System.printString(new String(b));
}
}
} else {
byte[] buffer=new byte[1024];
int numchars=q.read(buffer);
- if (numchars==0)
+ if (numchars==0) {
+ q.close();
taskexit(q{received});
- else {
+ } else {
String curr=(new String(buffer)).subString(0,numchars);
- System.printString(curr);
q.response.append(curr);
}
}
String href=new String("href=\"");
String searchstr=q.response.toString();
boolean cont=true;
+ q.outputFile();
+
while(cont) {
int mindex=searchstr.indexOf(href,index);
if (mindex!=-1) {
return path;
}
+ public void outputFile() {
+ StringBuffer sb=new StringBuffer(hostname);
+ sb.append(path);
+ FileOutputStream fos=new FileOutputStream(sb.toString().replace('/','#'));
+ fos.write(response.toString().getBytes());
+ fos.close();
+ }
+
public String makewebcanonical(String page) {
StringBuffer b=new StringBuffer(getHostName(page));
b.append("/");
int nextindex=page.indexOf('/',beginindex+1);
if ((beginindex==-1)||(nextindex==-1))
return new String("index.html");
- return page.subString(nextindex+1, page.length()-1);
+ return page.subString(nextindex+1, page.length());
}
}
}
Thread.sleep(2);
}
String hostname=q.getHostName();
+ System.printString("Processing ");
+ System.printString(hostname);
+ System.printString(" ");
+ System.printString(q.getPath());
+ System.printString("\n");
Socket s=new Socket(hostname, 80);
requestQuery(q, s);
readResponse(q, s);
+ q.outputFile();
processPage(q, ql);
s.close();
}
if ((numchars==1)) {
if (b[0]=='\r') {
state++;
- System.printString(new String(b));
}
} else
return;
state++;
else
state=0;
- System.printString(new String(b));
} else return;
} else if (state==2) {
byte[] b=new byte[1];
state++;
else
state=0;
- System.printString(new String(b));
} else return;
} else if (state==3) {
byte[] b=new byte[1];
state++;
else
state=0;
- System.printString(new String(b));
} else return;
}
} else {
return;
else {
String curr=(new String(buffer)).subString(0,numchars);
- System.printString(curr);
q.response.append(curr);
}
}
Query firstquery=new Query(firstmachine, firstpage);
toprocess.addQuery(firstquery);
QueryThread qt1=new QueryThread(toprocess, ql);
- qt1.run();
- // qt1.start();
- //QueryThread qt2=new QueryThread(toprocess, ql);
- //qt2.start();
- //QueryThread qt3=new QueryThread(toprocess, ql);
- //qt3.start();
- //while(true)
- // Thread.sleep(1000000);
+ qt1.start();
+ QueryThread qt2=new QueryThread(toprocess, ql);
+ qt2.start();
+ QueryThread qt3=new QueryThread(toprocess, ql);
+ qt3.start();
+ while(true)
+ Thread.sleep(1000000);
}