-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSearch.java
More file actions
104 lines (88 loc) · 2.14 KB
/
WebSearch.java
File metadata and controls
104 lines (88 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
SPlaT: Search that blocks until certain conditions are met.
written by Shafik Amin, 6-3-2003
*/
/** Imports **/
import java.util.*;
import java.net.*;
import java.io.*;
public class WebSearch extends BasicWebSearch
{
/* Empty Constructor, needs to be set */
public WebSearch()
{
super();
}
/* Constructor, num: number of files to download */
public WebSearch(int num, String fullURL) throws MalformedURLException
{
super(fullURL);
setDownloads(num);
}
public static String description()
{
return "Follows all links looking for desired file-types";
}
/* override the default shouldExplore method, to make sure to end the search when needed */
public /* synchronized */ boolean shouldExplore(String url)
{
if (stop)
return false;
if (!shouldStop())
return super.shouldExplore(url);
else
{
//System.out.println("Returning false in shouldExplore...");
return false;
}
}
/* similar overriding to shouldExplore */
public /* synchronized */ boolean shouldWriteToDisk(String url)
{
if (stop)
return false;
if (!shouldStop())
return super.shouldWriteToDisk(url);
else
{
System.out.println("Returning false in shouldWriteToDisk...");
return false;
}
}
public /* synchronized */ boolean shouldStop()
{
//return (getPreWrittenCount() == getDownloads() &&
// getWriteCount() >= getDownloads()) ||
// isTimeUp();
return stop || (getPreWrittenCount() >= getDownloads()) ||
isTimeUp();
}
/** Test Driver **/
public static void main(String[] args)
{
String toTest = "http://www.u.arizona.edu/~gergelyk/splat/spider.html";
int number = 50;
int seconds = 6;
int numloops = 1;
File dl = new File("Test");
dl.mkdirs();
for (int i = 0; i < numloops; i++)
{
try
{
WebSearch w = new WebSearch();
w.setWebsite(toTest);
w.setDownloads(number);
w.setDepth(4);
w.setTime(seconds); // # of seconds
w.setDownloadLocation(dl);
w.startSearch();
System.out.println("Search ended!!");
}
catch (Exception e)
{
System.out.println(e);
}
}
}
}