InputStream transferTo

先日の
oboe2uran.hatenablog.com

Java9 以上なら、
java.io.InputStream.transferTo(OutputStream out) throws IOException 使えば、

List<String> list;

// list に送信するものを入れてから

try(ByteArrayOutputStream out = new ByteArrayOutputStream()){
   ScriptExecutor.runStream(()->"python script/test.py"
   , ()->list.stream().map(e->Unicodes.encode(e) + "\n").collect(Collectors.toList())
   , ThrowableConsumer.of(i->i.transferTo(out))
   , (t, e)->{
      System.out.println("stderr : " + t );
      e.printStackTrace();
   });
   String response = out.toString();

}catch(IOException ex){
   ex.printStackTrace();
}finally{
}