public class WebResponseWrapper extends WebResponse
WebResponse
interface that can be subclassed
by developers wishing to adapt a particular WebResponse.
This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped
web response object.Constructor and Description |
---|
WebResponseWrapper(WebResponse webResponse)
Constructs a WebResponse object wrapping provided WebResponse.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanUp()
Clean up the response data.
|
void |
defaultCharsetUtf8()
Deprecated.
as of version 4.0.0; use
WebRequest.setDefaultResponseContentCharset(Charset) instead |
InputStream |
getContentAsStream()
Returns the response content as an input stream.
|
InputStream |
getContentAsStreamWithBomIfApplicable()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
String |
getContentAsString()
Returns the response content as a string, using the charset/encoding specified in the server response.
|
String |
getContentAsString(Charset encoding)
Returns the response content as a string, using the specified charset,
rather than the charset/encoding specified in the server response.
|
Charset |
getContentCharset()
Returns the content charset for this response, even if no charset was specified explicitly.
|
Charset |
getContentCharsetOrNull()
Deprecated.
as of version 4.0.0; use
getContentCharset() instead |
long |
getContentLength()
Returns length of the content data.
|
String |
getContentType()
Returns the content type returned from the server, e.g.
|
Charset |
getHeaderContentCharset()
Returns the content charset specified explicitly in the
Content-Type header
or null if none was specified. |
long |
getLoadTime()
Returns the time it took to load this web response, in milliseconds.
|
List<NameValuePair> |
getResponseHeaders()
Returns the response headers as a list of
NameValuePair s. |
String |
getResponseHeaderValue(String headerName)
Returns the value of the specified response header.
|
int |
getStatusCode()
Returns the status code that was returned by the server.
|
String |
getStatusMessage()
Returns the status message that was returned from the server.
|
WebRequest |
getWebRequest()
Returns the request used to load this response.
|
boolean |
isSuccess() |
boolean |
isSuccessOrUseProxy() |
boolean |
isSuccessOrUseProxyOrNotModified() |
boolean |
wasContentCharsetTentative()
Returns whether the charset of the previous call to
WebResponse.getContentCharset() was "tentative". |
getBlockReason, markAsBlocked, wasBlocked
public WebResponseWrapper(WebResponse webResponse) throws IllegalArgumentException
webResponse
- the webResponse that does the real workIllegalArgumentException
- if the webResponse is null
public long getContentLength()
getContentLength
in class WebResponse
public InputStream getContentAsStream() throws IOException
getContentAsStream
in class WebResponse
IOException
- in case of IOProblemspublic boolean wasContentCharsetTentative()
WebResponse.getContentCharset()
was "tentative".
A charset is classed as "tentative" if its detection is prone to false positive/negatives.
For example, HTML meta-tag sniffing can be fooled by text that looks-like-a-meta-tag inside JavaScript code (false positive) or if the meta-tag is after the first 1024 bytes (false negative). The default behavior of this method is to return wasContentCharsetTentative() on the wrapped webResponse object.
wasContentCharsetTentative
in class WebResponse
true
if the charset of the previous call to WebResponse.getContentCharset()
was
"tentative".public String getContentAsString()
getContentAsString
in class WebResponse
public String getContentAsString(Charset encoding)
getContentAsString
in class WebResponse
encoding
- the charset/encoding to use to convert the response content into a stringpublic Charset getHeaderContentCharset()
Content-Type
header
or null
if none was specified.
The default behavior of this method is to return getHeaderContentCharset() on the wrapped webResponse object.getHeaderContentCharset
in class WebResponse
null
if none was specified@Deprecated public Charset getContentCharsetOrNull()
getContentCharset()
insteadnull
if none was specified.
The default behavior of this method is to return getContentCharsetOrNull() on the wrapped webResponse object.getContentCharsetOrNull
in class WebResponse
null
if none was specifiedpublic Charset getContentCharset()
This method always returns a valid charset. This method first checks the Content-Type
header or in the content BOM for viable charset. If not found, it attempts to determine the
charset based on the type of the content. As a last resort, this method returns the
value of WebRequest.getDefaultResponseContentCharset()
which is
StandardCharsets.UTF_8
by default.
The default behavior of this method is to return getContentCharset() on the wrapped webResponse object.
getContentCharset
in class WebResponse
public String getContentType()
getContentType
in class WebResponse
public long getLoadTime()
getLoadTime
in class WebResponse
public List<NameValuePair> getResponseHeaders()
NameValuePair
s.
The default behavior of this method is to return getResponseHeaders() on the wrapped webResponse object.getResponseHeaders
in class WebResponse
NameValuePair
spublic String getResponseHeaderValue(String headerName)
getResponseHeaderValue
in class WebResponse
headerName
- the name of the header whose value is to be returnednull
if no response header exists with this namepublic int getStatusCode()
getStatusCode
in class WebResponse
public String getStatusMessage()
getStatusMessage
in class WebResponse
public WebRequest getWebRequest()
getWebRequest
in class WebResponse
public void cleanUp()
cleanUp
in class WebResponse
@Deprecated public void defaultCharsetUtf8()
WebRequest.setDefaultResponseContentCharset(Charset)
insteaddefaultCharsetUtf8
in class WebResponse
public InputStream getContentAsStreamWithBomIfApplicable() throws IOException
WebResponse
getContentAsStreamWithBomIfApplicable
in class WebResponse
IOException
- in case of IO problemspublic boolean isSuccess()
isSuccess
in class WebResponse
public boolean isSuccessOrUseProxy()
isSuccessOrUseProxy
in class WebResponse
public boolean isSuccessOrUseProxyOrNotModified()
isSuccessOrUseProxyOrNotModified
in class WebResponse
Copyright © 2002–2024 Gargoyle Software Inc.. All rights reserved.