Example usage for android.webkit WebResourceResponse getData

List of usage examples for android.webkit WebResourceResponse getData

Introduction

In this page you can find the example usage for android.webkit WebResourceResponse getData.

Prototype

public InputStream getData() 

Source Link

Document

Gets the input stream that provides the resource response's data.

Usage

From source file:com.concentricsky.android.khanacademy.util.CaptionManager.java

private List<Caption> parseAPIResponse(WebResourceResponse response) {
    Log.d(LOG_TAG, "parseAPIResponse");
    List<Caption> result = null;
    if (response != null) {
        ObjectMapper mapper = new ObjectMapper();
        try {/*from ww  w .  j a va2s  .  co  m*/
            result = mapper.readValue(response.getData(), new TypeReference<List<Caption>>() {
            });
            Log.d(LOG_TAG, " result length is " + result.size());
        } catch (JsonParseException e) {
            // At 5pm on a Thursday, I encountered this exception. Did a little digging, and the response turned
            // out to contain this: 
            // <html> <body> <div style="text-align: center; padding-top: 200px">
            //     Amara is currently unavailable for scheduled maintenance. The site will be back shortly.
            // </div> </body> </html>

            // Another at 2:45 Tuesday:  Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
            // This has happened more than once around the same time. Caught it again today, Tue 12/4, at about 3:00.

            // At any rate, these all fall into the "failed to download" category rather than the "none exist" category.
            e.printStackTrace();
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        Log.d(LOG_TAG, " response was null");
    }
    return result;
}