-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputfromdataset.java
124 lines (110 loc) · 2.88 KB
/
inputfromdataset.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
115
116
117
118
119
120
121
122
123
124
import java.util.*;
import java.io.*;
class inputfromdataset{
StringBuilder ipprefix = new StringBuilder();
String sipPrefix;
String dipPrefix;
int spnf;
int spnl;
int dpnf;
int dpnl;
classifier classifier1;
inputfromdataset(){
classifier1 = new classifier(752);
File file = new File("acl1.txt");
int count = 0;
try{
Scanner sc = new Scanner(file);
while(sc.hasNextLine()){
String Rule = sc.nextLine();
printrule(Rule,count);
count++;
}
}
catch(Exception e){
System.out.println("file not found");
}
}
public void printrule(String Rule,int count){
int spacecount = 0;
StringBuilder sb = new StringBuilder();
for(int i=0;i<Rule.length();i++){
if(Rule.charAt(i)=='.'){
constructipprefix(sb);
sb = new StringBuilder();
}
else if(Rule.charAt(i)=='/'){
constructipprefix(sb);
sb = new StringBuilder();
if(Rule.charAt(i+2)==' '){
displayprefix(Rule.substring(i+1,i+2));
i++;
}
else{
displayprefix(Rule.substring(i+1,i+3));
i++;
i++;
}
}
else if(Rule.charAt(i)==' '){
if(spacecount == 3 ||spacecount == 4 ||spacecount == 5 || spacecount == 7){
if(spacecount == 3){
spnf = Integer.parseInt(sb.toString());
}
if(spacecount == 4){
spnl = Integer.parseInt(sb.toString());
}
if(spacecount == 5){
dpnf = Integer.parseInt(sb.toString());
}
if(spacecount == 7){
dpnl = Integer.parseInt(sb.toString());
}
System.out.println(Integer.parseInt(sb.toString()));
sb = new StringBuilder();
}
spacecount++;
if(spacecount==8){
classifier1.rulesArray[count]= new rule(sipPrefix,dipPrefix,spnf,spnl,dpnf,dpnl);
sipPrefix=null;
break;
}
}
else if(Rule.charAt(i)!=':'){
sb.append(Character.toString(Rule.charAt(i)));
}
}
//System.out.println(Integer.parseInt(sb.toString()));
}
public void constructipprefix(StringBuilder sb){
int val = Integer.parseInt(sb.toString());
StringBuilder temp = new StringBuilder();
while (val > 0) {
// storing remainder in binary array
temp.insert(0,Integer.toString(val % 2));
val = val / 2;
}
int count = temp.length();
for(int i=0;i<8-count;i++){
ipprefix.append("0");
}
ipprefix.append(temp.toString());
}
public void displayprefix(String str){
StringBuilder prefix = new StringBuilder();
int count = Integer.parseInt(str);
for(int i=0;i<count;i++){
System.out.print(ipprefix.toString().charAt(i));
prefix.append(ipprefix.toString().charAt(i));
}
prefix.append("*");
if(sipPrefix==null){
sipPrefix=prefix.toString();
}
else{
dipPrefix=prefix.toString();
}
System.out.println("*");
ipprefix = new StringBuilder();
}
}