I'm trying to stream the ouput of ProcessBuilder via the response object. Right now I get the output on my client side only after the process is completed. I would like to see the output on client side being printed at the same time. Currently this is my code and it prints out everything in the client side (POSTMAN) after the process is done.
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException, WebApplicationException {
String line;
Writer writer = new BufferedWriter(new OutputStreamWriter(os));
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
try {
while ((line = input.readLine()) != null) {
writer.write("TEST");
writer.write(line);
writer.flush();
os.flush();;
}
} finally {
os.close();
writer.close();
}
}
};
return Response.ok(stream).build();