-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskReadE2.java
116 lines (94 loc) · 4.74 KB
/
TaskReadE2.java
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
105
106
107
108
109
110
111
112
113
114
package ParcoursDeGrapheSansMemoireTotal;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.LockfreeQueue;
public class TaskReadE2 extends Thread{
LockfreeQueue<String> RepererMot;
HashMap<String,Couple> rempli;
LockfreeQueue<Trio> UrlEtPage;
int Generation;
TaskReadE2(LockfreeQueue<String> RepererMot,HashMap<String,Couple> rempli,LockfreeQueue<Trio> UrlEtPage,int Generation){
this.RepererMot=RepererMot;
this.rempli=rempli;
this.UrlEtPage=UrlEtPage;
this.Generation=Generation;
}
public void run() {
while (!RepererMot.isEmpty()){
BufferedReader reader = null;
try {
String _url=RepererMot.take();
if (this.rempli.containsKey(_url)){
Couple c= this.rempli.get(_url);
if (c.i>this.Generation){continue;}
}
if ((_url==null)) {
continue ;
}
boolean pasunedate=((_url.startsWith("/wiki/")) && !(_url.equals("/wiki/Article_nominations"))&&!(_url.equals("/wiki/Wizards.com"))&&
!(_url.endsWith("/Legends")) && !(_url.endsWith("/Canon")) &&!(_url.startsWith("/wiki/LEGO"))&&
!(_url.startsWith("/wiki/Wookieepedia")) &&
!(_url.startsWith("/wiki/Category")) &&
!(_url.startsWith("/wiki/Forum")) &&
!(_url.startsWith("/wiki/Special:")) &&
!(_url.equals("/wiki/Executor")) && !(_url.equals("/wiki/Star_Wars_Legends")) && !(_url.equals("/wiki/Main_Page")) && !(_url.equals("/wiki/Local_Sitemap")) && !(_url.equals("/wiki/Help:Contents")) &&
!(_url.startsWith("/wiki/Talk:")) &&
!(_url.startsWith("/wiki/List_of_Star")) &&
!(_url.startsWith("/wiki/Template:")) &&
!(_url.startsWith("/wiki/The_Official_Star_Wars")) &&
!(_url.startsWith("/wiki/New_Jedi_Order")) && !(_url.startsWith("/wiki/Jedi")) && !(_url.startsWith("/wiki/Sith")) &&
!(_url.startsWith("/wiki/Fate_of_the_Jedi")) &&
!(_url.startsWith("/wiki/File:")) &&
!(_url.startsWith("/wiki/Article")) &&
!(_url.equals("/wiki/Lightsaber_combat")) && !(_url.equals("/wiki/Galactic_Republic")) && !(_url.equals("/wiki/The_Force")) && !(_url.equals("/wiki/The_galaxy")) && !(_url.equals("/wiki/Timeline_of_galactic_history")) && !(_url.equals("/wiki/Clone_Wars")) && !(_url.equals("/wiki/Grand_Army_of_the_Republic")) && !(_url.equals("/wiki/Confederacy_of_Independent_Systems")) &&
!(_url.startsWith("_url")) &&
!(_url.startsWith("/wiki/Star_Wars")) && !(_url.startsWith("/wiki/StarWars")) &&
!(_url.startsWith("/wiki/Encyclopedia_")) &&
!(_url.startsWith("/wiki/Databank_")) &&
!(_url.startsWith("/wiki/LEGO_Star_Wars")) &&
!(_url.startsWith("/wiki/William_Shakespeare")) &&
!(_url.startsWith("/wiki/Attack_of_the_Clones_")));
if(pasunedate){
for (int i = 1980; i<2018; i++){
pasunedate = pasunedate && (!_url.equals("/wiki/"+i));
}}
if(!pasunedate){
Couple c=new Couple(false,-1);
rempli.put(_url, c);
continue;}
URL url = new URL("http://starwars.wikia.com"+_url);
URLConnection urlConnection = url.openConnection();
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
String page=sb.toString();
Trio t= new Trio (_url,page,Generation);
UrlEtPage.add(t);
//System.out.println("+1 de generation"+this.Generation);
} catch (IOException ex) {
Logger.getLogger(LirePage.class.getName()).log(Level.SEVERE, null, ex);
continue;
}
finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException ex) {
Logger.getLogger(LirePage.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}