19 package org.sleuthkit.autopsy.report;
21 import java.io.BufferedWriter;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.OutputStreamWriter;
25 import java.io.Writer;
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.logging.Level;
32 import org.openide.util.NbBundle;
40 class FileReportText
implements FileReportModule {
41 private static final Logger logger = Logger.getLogger(FileReportText.class.getName());
42 private String reportPath;
44 private static final String FILE_NAME =
"file-report.txt";
46 private static FileReportText instance;
49 public static synchronized FileReportText getDefault() {
50 if (instance == null) {
51 instance =
new FileReportText();
57 public void startReport(String baseReportDir) {
58 this.reportPath = baseReportDir + FILE_NAME;
60 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(this.reportPath)));
61 }
catch (IOException ex) {
62 logger.log(Level.WARNING,
"Failed to create report text file", ex);
67 public void endReport() {
71 }
catch (IOException ex) {
72 logger.log(Level.WARNING,
"Could not close output writer when ending report.", ex);
77 private String getTabDelimitedList(List<String> list) {
78 StringBuilder output =
new StringBuilder();
79 Iterator<String> it = list.iterator();
81 output.append(it.next()).append((it.hasNext() ?
"\t" : System.lineSeparator()));
83 return output.toString();
87 public void startTable(List<FileReportDataTypes> headers) {
88 List<String> titles =
new ArrayList<>();
89 for(FileReportDataTypes col : headers) {
90 titles.add(col.getName());
93 out.write(getTabDelimitedList(titles));
94 }
catch (IOException ex) {
95 logger.log(Level.WARNING,
"Error when writing headers to report file: {0}", ex);
100 public void addRow(AbstractFile toAdd, List<FileReportDataTypes> columns) {
101 List<String> cells =
new ArrayList<>();
102 for(FileReportDataTypes type : columns) {
103 cells.add(type.getValue(toAdd));
106 out.write(getTabDelimitedList(cells));
107 }
catch (IOException ex) {
108 logger.log(Level.WARNING,
"Error when writing row to report file: {0}", ex);
113 public void endTable() {
115 out.write(System.lineSeparator());
116 }
catch (IOException ex) {
117 logger.log(Level.WARNING,
"Error when closing table: {0}", ex);
122 public String getName() {
123 return NbBundle.getMessage(this.getClass(),
"FileReportText.getName.text");
127 public String getDescription() {
128 return NbBundle.getMessage(this.getClass(),
"FileReportText.getDesc.text");
132 public String getRelativeFilePath() {