-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhpPagesSize.java
executable file
·108 lines (83 loc) · 3.04 KB
/
PhpPagesSize.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class PhpPagesSize {
private void analyzeTimeOutPagesSize(String path) {
try {
BufferedReader in = new BufferedReader(new FileReader(path));
String str, urlPage = "";
int otherPages = 0, imagePages = 0, cssFiles = 0, noFoundPages=0;
while ((str = in.readLine()) != null) {
if (str.contains("/index.php?")) {
String timeoutValue;
if (str.contains(" - POST")) {
timeoutValue = str.substring(
str.indexOf("POST - ") + 6,
str.indexOf("POST - ") + 6 + 4);
} else {
timeoutValue = str.substring(str.indexOf("GET - ") + 6,
str.indexOf("GET - ") + 6 + 4);
}
timeoutValue = timeoutValue.replace("-", "");
int timeout = Integer.parseInt(timeoutValue.trim());
if (timeout > 710) {
urlPage = str.substring(str.indexOf("/index.php?"),
str.length());
if (urlPage.contains("title=Image:"))
imagePages++;
else if (urlPage.contains("title=MediaWiki:Common.css")
|| urlPage
.contains("title=MediaWiki:Monobook.css"))
cssFiles++;
else
otherPages++;
try {
HttpURLConnection conn = (HttpURLConnection) new URL(
"http://10.143.42.7" + urlPage)
.openConnection();
InputStream input = conn.getInputStream();
// long size = input.available();
// System.out.println("PAGE "+urlPage+" SIZE: "+size);
BufferedReader buffer = new BufferedReader(
new InputStreamReader(input));
String aux = "", pageText = "";
while ((aux = buffer.readLine()) != null) {
pageText = pageText + aux;
}
System.out.println("PAGE " + urlPage + " TIMEOUT: "+timeout+" SIZE: "+ pageText.getBytes().length);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println(">> ERROR URL not Found "+e.getMessage());
noFoundPages++;
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(">> ERROR URL not Found "+e.getMessage());
noFoundPages++;
}
}
}
}
System.out.println("---------------------------------------------");
System.out.println("Number of image pages: " + imagePages);
System.out.println("Number of css files: " + cssFiles);
System.out.println("Number of other pages: " + otherPages);
System.out.println("Number of not found pages: " + noFoundPages);
System.out.println("---------------------------------------------");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]) {
PhpPagesSize main = new PhpPagesSize();
main.analyzeTimeOutPagesSize("./wikijector/log.txt");
}
}