-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathOutputWriter.java
More file actions
37 lines (30 loc) · 1.13 KB
/
OutputWriter.java
File metadata and controls
37 lines (30 loc) · 1.13 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
package analyzer;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
/**
* The {@link OutputWriter} serializes the analyzer output and writes it files in the given output path.
*
* @see <a href="https://exercism.org/docs/building/tooling/analyzers/interface">The analyzer interface in the Exercism documentation</a>
*/
class OutputWriter {
private final Path outputPath;
OutputWriter(Path outputPath) {
this.outputPath = outputPath;
}
void write(Output output) throws IOException {
writeAnalysis(output.analysis());
writeTags(output.tags());
}
private void writeAnalysis(Output.Analysis analysis) throws IOException {
write(OutputSerializer.serialize(analysis), this.outputPath.resolve("analysis.json"));
}
private void writeTags(Output.Tags tags) throws IOException {
write(OutputSerializer.serialize(tags), this.outputPath.resolve("tags.json"));
}
private void write(String contents, Path path) throws IOException {
try (var writer = new FileWriter(path.toFile())) {
writer.write(contents);
}
}
}