2017-07-21 8 views
0

StreamingOutputを使用して出力をストリームできることはわかっています。しかし、私はMessageBodyWriterでもそれを行うことができますか?私が次のように実装している場合: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); 
     } 
    }); 
} 

すべての出力が同時に到着している(つまりストリーミングしていない)ようです。すべての手がかりは?

+0

この問題を確認するhttps://stackoverflow.com/questions/41483716/chunkedinput-not-working-in-jersey – gladiator

答えて

0

この質問につきまとう不思議なことに、ストリーミングに必要なデータがないためストリーミングしていませんでした。標準では、私は明らかにヒットしませんでした(https://github.com/jersey/jersey/blob/master/core-common/src/main/java/org/glassfish/jersey/message/MessageProperties.javaから)

/** 
* The default buffer size ({@value}) for I/O operations on byte and character 
* streams. 
*/ 
public static final int IO_DEFAULT_BUFFER_SIZE = 8192; 

です。

関連する問題