Example usage for org.apache.http.client.cache Resource getInputStream

List of usage examples for org.apache.http.client.cache Resource getInputStream

Introduction

In this page you can find the example usage for org.apache.http.client.cache Resource getInputStream.

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Returns an InputStream from which the response body can be read.

Usage

From source file:org.apache.http.impl.client.cache.TestHttpCacheEntrySerializers.java

private byte[] resourceToBytes(Resource res) throws IOException {
    InputStream inputStream = res.getInputStream();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    int readBytes;
    byte[] bytes = new byte[8096];
    while ((readBytes = inputStream.read(bytes)) > 0) {
        outputStream.write(bytes, 0, readBytes);
    }//from   w ww. j ava  2  s .  c  o m

    byte[] byteData = outputStream.toByteArray();

    inputStream.close();
    outputStream.close();

    return byteData;
}