-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.java
More file actions
203 lines (154 loc) · 5.41 KB
/
properties.java
File metadata and controls
203 lines (154 loc) · 5.41 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ningluo
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ningluo
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.PrimitiveIterator.OfDouble;
import org.omg.CORBA.PUBLIC_MEMBER;
public class properties {
private int port = 6789;
private int CacheSize = 8096;
private HashMap<String , String> NameMap;
private int poolsize = 50;
public properties() {
NameMap = new HashMap<String,String>();
}
// public static void main(String[] args) throws IOException {
// String file = "/Users/ningluo/Desktop/networks/assignment/assignment3/config.conf";
// config(file);
// System.out.println(getServerDic("cicada.cs.yale.edu"));
// System.out.println(getServerPort());
// }
//
public void config(String filename) throws IOException {
File file = new File(util.CONFIG_PATH+"/"+filename);
GetPortInfo(file);
GetCacheInfo(file);
buildNameMap(file);
setPoolSize(file);
}
public int getCacheSize(){
return CacheSize;
}
public int getServerPort(){
return port;
}
public int getpoolSize(){
System.out.println(poolsize);
return poolsize;
}
public String getServerDic(String ServerName){
return NameMap.get(ServerName);
}
public HashMap getNameMap(){
return NameMap;
}
private void buildNameMap(File file) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null) {
if (st.length() == 0) {
continue;
}
if (st.startsWith("<VirtualHost *:")) {
// System.out.println("yes");
st = br.readLine();
st = st.trim();
// System.out.println(st);
String[] prop = st.split(" +");
String DocumentRoot = prop[1];
if (DocumentRoot.length()>2) {
DocumentRoot =DocumentRoot.substring(0, DocumentRoot.length());
}
st = br.readLine();
st = st.trim();
prop = st.split(" +");
String ServerName= prop[1];
// System.out.println(ServerName+" "+DocumentRoot);
NameMap.put(ServerName, DocumentRoot);
}
}
br.close();
}
private void setPoolSize(File file) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
String st = br.readLine();
String[] poolInfo = st.split(" +");
while (st!= null ) {
if (poolInfo.length>1){
// System.out.println(poolInfo[0]);
if(poolInfo[0].equals("ThreadPoolSize")) {
System.out.println(poolInfo[1]);
poolsize = Integer.parseInt(poolInfo[1]);
return;
}
}
st = br.readLine();
poolInfo = st.split(" +");
}
}
private void GetPortInfo(File file) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
String st = br.readLine();
String[] portInfo = st.split(" +");
while (st.length()== 0 ||!portInfo[0].equals("Listen") ) {
st = br.readLine();
}
if (portInfo.length ==2) {
port = Integer.parseInt(portInfo[1]);
} else {
System.out.println("incorrect config file");
}
br.close();
}
private void GetCacheInfo(File file) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
String st = br.readLine();
//Debug.DEBUG(st);
String[] CacheInfo = st.split(" +");
while ((st.length()== 0 || !CacheInfo[0].equals("CacheSize")) && st != null ) {
//bug.DEBUG(st);
st = br.readLine();
CacheInfo = st.split(" +");
}
if (CacheInfo.length ==2 && CacheInfo[0]=="CacheSize") {
CacheSize = Integer.parseInt(CacheInfo[1]);
} else {
//ystem.out.println("incorrect config file");
}
br.close();
}
}
// st = st.trim();
// String[] prop = st.split(" +");
// if (prop.length > 1)
// System.out.println(prop[0]+":" + prop[1]);
// }
//
// while ((st = br.readLine()) != null)
// if (!st.startsWith("<") && st.length()>0){
// st = br.readLine())
// System.out.println(st);
// String[] prop = st.split("\\s+");
// System.out.println(prop[1]);
// System.out.println(prop[2]);
// }