Package com.azure.android.core.http
Class HttpResponse
- java.lang.Object
-
- com.azure.android.core.http.HttpResponse
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
BufferedHttpResponse
public abstract class HttpResponse extends java.lang.Object implements java.io.Closeable
The type representing response ofHttpRequest
. The body of theHttpResponse
is backed by an HTTP connection, the HTTP connections are limited resources. It is important to close the response body to avoid leaking of backing connection and associated resources, such leaking may ultimately cause the application to slow down or crash.HttpResponse
implementsCloseable
, invokingCloseable.close()
will close the response body. The body must be closed by calling one of the following methods:- HttpResponse::close()
- HttpResponse::getBody().close()
- HttpResponse::getBodyAsByteArray()
- HttpResponse::getBodyAsString()
- HttpResponse::getBodyAsString(Charset)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpResponse(HttpRequest request)
Creates a HttpResponse.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description HttpResponse
buffer()
Get a new Response object wrapping this response with it's content buffered into memory.void
close()
Closes the response content stream, if any.abstract java.io.InputStream
getBody()
Get theInputStream
producing response content chunks.abstract byte[]
getBodyAsByteArray()
Get the response content as a byte[].abstract java.lang.String
getBodyAsString()
Get the response content as a string.abstract java.lang.String
getBodyAsString(java.nio.charset.Charset charset)
Get the response content as a string.abstract HttpHeaders
getHeaders()
Get all response headers.abstract java.lang.String
getHeaderValue(java.lang.String name)
Lookup a response header with the provided name.HttpRequest
getRequest()
Get the request which resulted in this response.abstract int
getStatusCode()
Get the response status code.
-
-
-
Constructor Detail
-
HttpResponse
protected HttpResponse(HttpRequest request)
Creates a HttpResponse.- Parameters:
request
- The request which resulted in this response.
-
-
Method Detail
-
getStatusCode
public abstract int getStatusCode()
Get the response status code.- Returns:
- the response status code
-
getHeaderValue
public abstract java.lang.String getHeaderValue(java.lang.String name)
Lookup a response header with the provided name.- Parameters:
name
- the name of the header to lookup.- Returns:
- the value of the header, or null if the header doesn't exist in the response.
-
getHeaders
public abstract HttpHeaders getHeaders()
Get all response headers.- Returns:
- the response headers
-
getBody
public abstract java.io.InputStream getBody()
Get theInputStream
producing response content chunks.- Returns:
- The response's content as a stream.
-
getBodyAsByteArray
public abstract byte[] getBodyAsByteArray()
Get the response content as a byte[].- Returns:
- this response content as a byte[]
-
getBodyAsString
public abstract java.lang.String getBodyAsString()
Get the response content as a string.- Returns:
- This response content as a string
-
getBodyAsString
public abstract java.lang.String getBodyAsString(java.nio.charset.Charset charset)
Get the response content as a string.- Parameters:
charset
- the charset to use as encoding- Returns:
- This response content as a string
-
getRequest
public final HttpRequest getRequest()
Get the request which resulted in this response.- Returns:
- the request which resulted in this response.
-
buffer
public HttpResponse buffer()
Get a new Response object wrapping this response with it's content buffered into memory.- Returns:
- the new Response object
-
close
public void close()
Closes the response content stream, if any.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-