-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeautifier.java
More file actions
66 lines (52 loc) · 1.47 KB
/
Beautifier.java
File metadata and controls
66 lines (52 loc) · 1.47 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
public class Beautifier {
public static void main(String[] args){
if(args.length < 2) {
System.out.println("Usage:\n java Beautifier [COLOR=NEW_COLOR][FILENAME]");
System.exit(1);
}
String filename = args[args.length - 1];
ArrayList<Pair> pairs = new ArrayList<>();
for(int i = 0; i < args.length - 1; i++)
pairs.add(new Pair(args[i].split("=")[0], args[i].split("=")[1]));
StringBuilder sb = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String file = sb.toString();
br.close();
for(int i = 0; i < pairs.size(); i++)
file = file.replace(pairs.get(i).getKey(), pairs.get(i).getValue());
FileWriter fstream = new FileWriter(filename);
BufferedWriter out = new BufferedWriter(fstream);
out.write(file);
out.close();
}
catch (Exception e){
System.out.println("An error has occured: " + e.getMessage());
}
}
}
class Pair {
String key;
String value;
public Pair(String key, String value){
this.key = key;
this.value = value;
}
public String getKey(){
return key;
}
public String getValue(){
return value;
}
}