-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserLog.java
More file actions
71 lines (61 loc) · 1.33 KB
/
ParserLog.java
File metadata and controls
71 lines (61 loc) · 1.33 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* @author Cole Amick
* Date: 01.29.2014
*/
public class ParserLog {
private File file;
private boolean logBit;
private OutputStream fileOutStream;
/**
* Creates a log file
*
* @throws FileNotFoundException
*/
public ParserLog(boolean logBit) throws FileNotFoundException {
this.logBit = logBit;
if (logBit) {
System.out.println("ParserLog.txt created with logging enabled");
file = new File("./ParserLog.txt");
fileOutStream = new FileOutputStream(file);
} else
System.out.println("Logging disabled");
}
/**
* converts msg into bytes and writes the bytes to the log file adds new
* line character to msg
*
* @param msg
*/
public void logMsg(String msg) {
// add newline character
msg += '\n';
// get bytes
byte bytes[] = msg.getBytes();
// write bytes
if (logBit)
for (int i = 0; i < msg.length(); i++) {
try {
fileOutStream.write(bytes[i]);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* Closes log file
*/
public void closeLog() {
if (logBit)
try {
fileOutStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}