WebResourceResponsepublic class WebResourceResponse extends Object Encapsulates a resource response. Applications can return an instance of this
class from {@link WebViewClient#shouldInterceptRequest} to provide a custom
response when the WebView requests a particular resource. |
Fields Summary |
---|
private String | mMimeType | private String | mEncoding | private int | mStatusCode | private String | mReasonPhrase | private Map | mResponseHeaders | private InputStream | mInputStream |
Constructors Summary |
---|
public WebResourceResponse(String mimeType, String encoding, InputStream data)Constructs a resource response with the given MIME type, encoding, and
input stream. Callers must implement
{@link InputStream#read(byte[]) InputStream.read(byte[])} for the input
stream.
mMimeType = mimeType;
mEncoding = encoding;
mInputStream = data;
| public WebResourceResponse(String mimeType, String encoding, int statusCode, String reasonPhrase, Map responseHeaders, InputStream data)Constructs a resource response with the given parameters. Callers must
implement {@link InputStream#read(byte[]) InputStream.read(byte[])} for
the input stream.
this(mimeType, encoding, data);
setStatusCodeAndReasonPhrase(statusCode, reasonPhrase);
setResponseHeaders(responseHeaders);
|
Methods Summary |
---|
public java.io.InputStream | getData()Gets the input stream that provides the resource response's data.
return mInputStream;
| public java.lang.String | getEncoding()Gets the resource response's encoding.
return mEncoding;
| public java.lang.String | getMimeType()Gets the resource response's MIME type.
return mMimeType;
| public java.lang.String | getReasonPhrase()Gets the description of the resource response's status code.
return mReasonPhrase;
| public java.util.Map | getResponseHeaders()Gets the headers for the resource response.
return mResponseHeaders;
| public int | getStatusCode()Gets the resource response's status code.
return mStatusCode;
| public void | setData(java.io.InputStream data)Sets the input stream that provides the resource response's data. Callers
must implement {@link InputStream#read(byte[]) InputStream.read(byte[])}.
mInputStream = data;
| public void | setEncoding(java.lang.String encoding)Sets the resource response's encoding, for example UTF-8. This is used
to decode the data from the input stream.
mEncoding = encoding;
| public void | setMimeType(java.lang.String mimeType)Sets the resource response's MIME type, for example text/html.
mMimeType = mimeType;
| public void | setResponseHeaders(java.util.Map headers)Sets the headers for the resource response.
mResponseHeaders = headers;
| public void | setStatusCodeAndReasonPhrase(int statusCode, java.lang.String reasonPhrase)Sets the resource response's status code and reason phrase.
if (statusCode < 100)
throw new IllegalArgumentException("statusCode can't be less than 100.");
if (statusCode > 599)
throw new IllegalArgumentException("statusCode can't be greater than 599.");
if (statusCode > 299 && statusCode < 400)
throw new IllegalArgumentException("statusCode can't be in the [300, 399] range.");
if (reasonPhrase == null)
throw new IllegalArgumentException("reasonPhrase can't be null.");
if (reasonPhrase.trim().isEmpty())
throw new IllegalArgumentException("reasonPhrase can't be empty.");
for (int i = 0; i < reasonPhrase.length(); i++) {
int c = reasonPhrase.charAt(i);
if (c > 0x7F) {
throw new IllegalArgumentException(
"reasonPhrase can't contain non-ASCII characters.");
}
}
mStatusCode = statusCode;
mReasonPhrase = reasonPhrase;
|
|