Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
37 lines
1.0 KiB
Java
37 lines
1.0 KiB
Java
package com.ankurm.cloudstream;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Collects lines and writes them to output/NN-name.txt when closed. Tests assert the same values
|
|
* they print, so every number in the article is an assertion that fails the build when it stops being true.
|
|
*/
|
|
public final class Transcript implements AutoCloseable {
|
|
|
|
private final Path file;
|
|
private final List<String> lines = new ArrayList<>();
|
|
|
|
public Transcript(String name) {
|
|
this.file = Path.of(System.getProperty("user.dir"), "output", name + ".txt");
|
|
}
|
|
|
|
public Transcript line(String format, Object... args) {
|
|
lines.add(args.length == 0 ? format : String.format(format, args));
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void close() {
|
|
try {
|
|
Files.createDirectories(file.getParent());
|
|
Files.write(file, lines);
|
|
} catch (IOException e) {
|
|
throw new IllegalStateException(e);
|
|
}
|
|
}
|
|
}
|