InputStream will not reset to beginning

后端 未结 2 1465
情话喂你
情话喂你 2020-12-16 16:27
InputStream data = realResponse.getEntity().getContent();
byte[] preview = new byte[100];
data.read(preview, 0, 100);

// Now I want to refer to the

2条回答
  •  有刺的猬
    2020-12-16 16:45

    When you use mark() of the java.io.InputStream object you should check with the markSupported() method if your InputStream actually support using mark. According to the API the InputStream class doesn't, but the java.io.BufferedInputStream class does. Maybe you should embed your stream inside a BufferedInputStream object like:

    InputStream data = new BufferedInputStream(realResponse.getEntity().getContent());
    // data.markSupported() should return "true" now
    data.mark(some_size);
    // work with "data" now
    ...
    data.reset();
    

提交回复
热议问题