我知道我可以使用StreamingOutput流式传输我的输出。但是我也可以用MessageBodyWriter来做吗?如果我像这样实现它:
@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);
}
});
}
所有输出似乎都在同一时间到达(即不是流)。有什么线索吗?
发布于 2017-07-22 00:23:38
对于偶然发现这个问题的好奇者来说,它不是流,因为没有足够的数据来流。标准是
/**
* The default buffer size ({@value}) for I/O operations on byte and character
* streams.
*/
public static final int IO_DEFAULT_BUFFER_SIZE = 8192;
https://stackoverflow.com/questions/45231318
复制相似问题