forked from yegor256/quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.java
55 lines (48 loc) · 1.43 KB
/
Parser.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
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* This class is thread safe.
* <p>
* TODO - Better documentation for the class
*/
public class Parser {
private File file;
public synchronized void setFile(File file) {
this.file = file;
}
// TODO document public method
public synchronized File getFile() {
return this.file;
}
// TODO document public method
public String getContent() throws IOException {
FileInputStream inputStream = new FileInputStream(this.file);
String output = "";
int data;
while ((data = inputStream.read()) > 0) {
output += (char) data;
}
return output;
}
// TODO document public method
public String getContentWithoutUnicode() throws IOException {
FileInputStream inputStream = new FileInputStream(this.file);
String output = "";
int data;
while ((data = inputStream.read()) > 0) {
if (data < 0x80) {
output += (char) data;
}
}
return output;
}
// TODO document public method
public void saveContent(String content) throws IOException {
FileOutputStream outputStream = new FileOutputStream(this.file);
for (int i = 0; i < content.length(); i += 1) {
outputStream.write(content.charAt(i));
}
}
}