-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationProperties.java
More file actions
46 lines (40 loc) · 1.44 KB
/
ApplicationProperties.java
File metadata and controls
46 lines (40 loc) · 1.44 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
/**
* Singleton class to store application level properties
*/
public class ApplicationProperties {
private static ApplicationProperties instance;
private Properties property;
private int noOfPieces;
private ApplicationProperties(){
this.property = new Properties();
try(FileReader fileReader = new FileReader("Common.cfg");
BufferedReader bufferedReader = new BufferedReader(fileReader)){
String line = null;
while((line = bufferedReader.readLine()) != null){
String[] parts = line.split(" ");
property.setProperty(parts[0], parts[1]);
}
} catch (IOException fileNotFoundException) {
fileNotFoundException.printStackTrace();
}
int pieceSize = Integer.parseInt(this.property.getProperty("PieceSize", "0"));
int fileSize = Integer.parseInt(this.property.getProperty("FileSize", "0"));
this.noOfPieces = (int)Math.ceil(fileSize * 1.0 / pieceSize);
}
public static ApplicationProperties getInstance(){
if(instance == null){
instance = new ApplicationProperties();
}
return instance;
}
public String get(String key){
return property.getProperty(key, "");
}
public int getTotalPieces(){
return this.noOfPieces;
}
}