Skip to content

Commit

Permalink
Recordify WatchedOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 28, 2024
1 parent 21c24ae commit 4e39fc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,11 @@
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;

public class WatchedOutput {
record WatchedOutput(Thread thread, ByteArrayOutputStream stream) {

private static final Charset CHARSET = Charset.forName(System.getProperty("native.encoding"));

private final Thread thread;
private final ByteArrayOutputStream stream;

WatchedOutput(Thread thread, ByteArrayOutputStream stream) {
this.thread = thread;
this.stream = stream;
}

void join() throws InterruptedException {
thread.join();
}

public String getStreamAsString() {
String streamAsString() {
return stream.toString(CHARSET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ ProcessResult waitFor() throws InterruptedException {
}
finally {
try {
out.join();
out.thread().join();
}
finally {
err.join();
err.thread().join();
}
}
return new ProcessResult(exitCode, out.getStreamAsString(), err.getStreamAsString());
return new ProcessResult(exitCode, out.streamAsString(), err.streamAsString());
}
finally {
process.destroyForcibly();
Expand Down

0 comments on commit 4e39fc3

Please sign in to comment.