How to call readEntity on a Response twice?

后端 未结 1 1429
刺人心
刺人心 2020-12-31 09:41

What I\'m doing right now is resulting in a:

java.io.IOException: stream is closed

on the 2nd readEntity() since it closes the stream after

相关标签:
1条回答
  • 2020-12-31 10:38

    /You can use Response#bufferEntity(), which will allow you to read the entity stream multiple times.

    Response response = ...
    response.bufferEntity();
    String s = response.readEntity(String.class);
    MyEntity me = response.readEntity(MyEntity.class);
    response.close();
    

    Update

    After you read the entity with readEntity(), the result of the reading is cached and is available with the call to getEntity(). This information doesn't really answer the OP's question, but I thought it was useful information to add in.

    0 讨论(0)
提交回复
热议问题