01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.cpd;
04:
05: import java.io.*;
06:
07: /**
08: * @author Philippe T'Seyen
09: */
10: public class FileReporter {
11: private File reportFile;
12: private String encoding;
13:
14: public FileReporter(String encoding) {
15: this (null, encoding);
16: }
17:
18: public FileReporter(File reportFile) {
19: this (reportFile, System.getProperty("file.encoding"));
20: }
21:
22: public FileReporter(File reportFile, String encoding) {
23: this .reportFile = reportFile;
24: this .encoding = encoding;
25: }
26:
27: public void report(String content) throws ReportException {
28: try {
29: Writer writer = null;
30: try {
31: OutputStream outputStream;
32: if (reportFile == null) {
33: outputStream = System.out;
34: } else {
35: outputStream = new FileOutputStream(reportFile);
36: }
37: writer = new BufferedWriter(new OutputStreamWriter(
38: outputStream, encoding));
39: writer.write(content);
40: } finally {
41: if (writer != null)
42: writer.close();
43: }
44: } catch (IOException ioe) {
45: throw new ReportException(ioe);
46: }
47: }
48: }
|