public static class HttpConnection.Response extends HttpConnection.Base<Connection.Response> implements Connection.Response
| Modifier and Type | Field and Description |
|---|---|
private java.io.InputStream |
bodyStream |
private java.nio.ByteBuffer |
byteData |
private java.lang.String |
charset |
private java.net.HttpURLConnection |
conn |
private java.lang.String |
contentType |
private boolean |
executed |
private boolean |
inputStreamRead |
private static java.lang.String |
LOCATION |
private static int |
MAX_REDIRECTS |
private int |
numRedirects |
private HttpConnection.Request |
req |
private int |
statusCode |
private java.lang.String |
statusMessage |
private static java.util.regex.Pattern |
xmlContentTypeRxp |
cookies, headers, method, url| Modifier | Constructor and Description |
|---|---|
(package private) |
Response()
Internal only! Creates a dummy HttpConnection.Response, useful for testing.
|
private |
Response(java.net.HttpURLConnection conn,
HttpConnection.Request request,
HttpConnection.Response previousResponse) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
body()
Get the body of the response as a plain string.
|
byte[] |
bodyAsBytes()
Get the body of the response as an array of bytes.
|
java.io.BufferedInputStream |
bodyStream()
Get the body of the response as a (buffered) InputStream.
|
Connection.Response |
bufferUp()
Read the body of the response into a local buffer, so that
Connection.Response.parse() may be called repeatedly on the
same connection response (otherwise, once the response is read, its InputStream will have been drained and
may not be re-read). |
java.lang.String |
charset()
Get the character set name of the response, derived from the content-type header.
|
HttpConnection.Response |
charset(java.lang.String charset)
Set / override the response character set.
|
java.lang.String |
contentType()
Get the response content type (e.g.
|
private static java.net.HttpURLConnection |
createConnection(HttpConnection.Request req) |
private static java.util.LinkedHashMap<java.lang.String,java.util.List<java.lang.String>> |
createHeaderMap(java.net.HttpURLConnection conn) |
(package private) static HttpConnection.Response |
execute(HttpConnection.Request req) |
(package private) static HttpConnection.Response |
execute(HttpConnection.Request req,
HttpConnection.Response previousResponse) |
Document |
parse()
Read and parse the body of the response as a Document.
|
private void |
prepareByteData() |
(package private) void |
processResponseHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> resHeaders) |
private void |
safeClose()
Call on completion of stream read, to close the body (or error) stream.
|
private static void |
serialiseRequestUrl(Connection.Request req) |
private static java.lang.String |
setOutputContentType(Connection.Request req) |
int |
statusCode()
Get the status code of the response.
|
java.lang.String |
statusMessage()
Get the status message of the response.
|
private static void |
writePost(Connection.Request req,
java.io.OutputStream outputStream,
java.lang.String boundary) |
addHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, urlclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, urlprivate static final int MAX_REDIRECTS
private static final java.lang.String LOCATION
private final int statusCode
private final java.lang.String statusMessage
@Nullable private java.nio.ByteBuffer byteData
@Nullable private java.io.InputStream bodyStream
@Nullable private java.net.HttpURLConnection conn
@Nullable private java.lang.String charset
@Nullable private final java.lang.String contentType
private boolean executed
private boolean inputStreamRead
private int numRedirects
private final HttpConnection.Request req
private static final java.util.regex.Pattern xmlContentTypeRxp
Response()
private Response(java.net.HttpURLConnection conn,
HttpConnection.Request request,
@Nullable
HttpConnection.Response previousResponse)
throws java.io.IOException
java.io.IOExceptionstatic HttpConnection.Response execute(HttpConnection.Request req) throws java.io.IOException
java.io.IOExceptionstatic HttpConnection.Response execute(HttpConnection.Request req, @Nullable HttpConnection.Response previousResponse) throws java.io.IOException
java.io.IOExceptionpublic int statusCode()
Connection.ResponsestatusCode in interface Connection.Responsepublic java.lang.String statusMessage()
Connection.ResponsestatusMessage in interface Connection.Responsepublic java.lang.String charset()
Connection.Responsecharset in interface Connection.Responsepublic HttpConnection.Response charset(java.lang.String charset)
Connection.Responsecharset in interface Connection.Responsecharset - to decode body aspublic java.lang.String contentType()
Connection.ResponsecontentType in interface Connection.Responsepublic Document parse() throws java.io.IOException
Connection.ResponseConnection.Response.bufferUp() first.parse in interface Connection.Responsejava.io.IOException - on errorprivate void prepareByteData()
public java.lang.String body()
Connection.Responsebody in interface Connection.Responsepublic byte[] bodyAsBytes()
Connection.ResponsebodyAsBytes in interface Connection.Responsepublic Connection.Response bufferUp()
Connection.ResponseConnection.Response.parse() may be called repeatedly on the
same connection response (otherwise, once the response is read, its InputStream will have been drained and
may not be re-read). Calling Connection.Response.body() or Connection.Response.bodyAsBytes() has the same effect.bufferUp in interface Connection.Responsepublic java.io.BufferedInputStream bodyStream()
Connection.ResponseThis method is useful for writing large responses to disk, without buffering them completely into memory first.
bodyStream in interface Connection.Responseprivate static java.net.HttpURLConnection createConnection(HttpConnection.Request req) throws java.io.IOException
java.io.IOExceptionprivate void safeClose()
private static java.util.LinkedHashMap<java.lang.String,java.util.List<java.lang.String>> createHeaderMap(java.net.HttpURLConnection conn)
void processResponseHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> resHeaders)
@Nullable private static java.lang.String setOutputContentType(Connection.Request req)
private static void writePost(Connection.Request req, java.io.OutputStream outputStream, @Nullable java.lang.String boundary) throws java.io.IOException
java.io.IOExceptionprivate static void serialiseRequestUrl(Connection.Request req) throws java.io.IOException
java.io.IOException