File size: 2,178 Bytes
6f3ebfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
package org.maltparser.parser;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.maltparser.core.exception.MaltChainedException;

public class Diagnostics {
//	protected final boolean diagnostics;
	protected final BufferedWriter diaWriter;
	
	public Diagnostics(String fileName) throws MaltChainedException {
		try {
			if (fileName.equals("stdout")) {
				diaWriter = new BufferedWriter(new OutputStreamWriter(System.out));
			} else if (fileName.equals("stderr")) {
				diaWriter = new BufferedWriter(new OutputStreamWriter(System.err));
			} else {
				diaWriter = new BufferedWriter(new FileWriter(fileName));
			}
		} catch (IOException e) {
			throw new MaltChainedException("Could not open the diagnostic file. ", e);
		}
//		this.diagnostics = (Boolean)manager.getOptionValue("singlemalt", "diagnostics");
//		openDiaWriter(manager.getOptionValue("singlemalt", "diafile").toString());
	}
	
//	public boolean isDiagnostics() {
//		return diagnostics;
//	}

	public BufferedWriter getDiaWriter() {
		return diaWriter;
	}
	
	public void writeToDiaFile(String message) throws MaltChainedException {
		try {
			getDiaWriter().write(message);
		} catch (IOException e) {
			throw new MaltChainedException("Could not write to the diagnostic file. ", e);
		}
	}
	
	public void closeDiaWriter() throws MaltChainedException {
		if (diaWriter != null) {
			try {
				diaWriter.flush();
				diaWriter.close();
			} catch (IOException e) {
				throw new MaltChainedException("Could not close the diagnostic file. ", e);
			}
		}
	}
	
//	public void openDiaWriter(String fileName) throws MaltChainedException {
//		if (diagnostics) {
//			try {
//				if (fileName.equals("stdout")) {
//					diaWriter = new BufferedWriter(new OutputStreamWriter(System.out));
//				} else if (fileName.equals("stderr")) {
//					diaWriter = new BufferedWriter(new OutputStreamWriter(System.err));
//				} else {
//					diaWriter = new BufferedWriter(new FileWriter(fileName));
//				}
//			} catch (IOException e) {
//				throw new MaltChainedException("Could not open the diagnostic file. ", e);
//			}
//		}
//	}
}