我对泽西岛的StreamingOutput有两个问题:
1)它是否已被jax-rs运行时缓冲?我已经看到了一些在覆盖write()方法时从OutputStream对象创建BufferedWriter的示例。但我想知道这是否真的有必要。
2)在流完成后,Jersey或jax-rs运行时是否会关闭OutputStream对象?
谢谢,
GEG
答案 0 :(得分:1)
为了获得最高效率,请考虑包装OutputStreamWriter 在BufferedWriter中,以避免频繁的转换器调用。 例如: http://docs.oracle.com/javase/6/docs/api/java/io/OutputStreamWriter.html
import javax.ws.rs.core.StreamingOutput;
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException,
WebApplicationException {
Writer writer = new BufferedWriter(new OutputStreamWriter(os));
writer.write(msg);
writer.flush();
}
};