I know I can stream my output using a StreamingOutput. But can I do it also with a MessageBodyWriter? If I implement it like this:
@Override
public void writeTo(HelloWorldRepresentation t, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
"Hello world".chars().forEach(i -> {
try {
entityStream.write(i);
entityStream.write('\n');
entityStream.flush();
Thread.sleep(1000);
} catch (Exception e) {
throw new WebApplicationException(e);
}
});
}
All output seems to arrive at the same time (i.e. not streaming). Any clues?