-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexer.java
More file actions
46 lines (46 loc) · 1.05 KB
/
Lexer.java
File metadata and controls
46 lines (46 loc) · 1.05 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.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* This class is thread safe.
*/
public class Lexer {
private File input;
public synchronized void setFile(File f) {
input = f;
}
public synchronized File file() {
return input;
}
public String readContent() throws IOException {
FileInputStream i = new FileInputStream(input);
String t = "";
int data;
while ((data = i.read()) > 0) {
t += (char) data;
}
return t;
}
public String readContentWOUnicode() throws IOException {
FileInputStream i = new FileInputStream(input);
String temp = "";
int data;
while ((data = i.read()) > 0) {
if (data < 0x80) {
temp += (char) data;
}
}
return temp;
}
public void saveContent(String text) {
FileOutputStream o = new FileOutputStream(input);
try {
for (int i = 0; i < text.length(); i += 1) {
o.write(text.charAt(i));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}