- java.lang.Object
-
- net.dongliu.cute.http.HTTPResponseContext
-
- 所有已实现的接口:
AutoCloseable
public class HTTPResponseContext extends Object implements AutoCloseable
Raw blocking http response. The http headers already received, the http body not consumed, can be get as InputStream. It you do not consume http response body, withtoStringResponse(),toBinaryResponse(),writeTo(Path)etc.., you need to close this raw response manually. This class is not thread-safe.- 作者:
- Liu Dong
-
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 HTTPResponseContextautoDecompress(boolean autoDecompress)If decompress http response body automatically.HTTPResponseContextcharset(Charset charset)Set response body read charset.voidclose()HTTPResponse<Void>discard()Consume and discard this response body.<T> HTTPResponse<T>handle(ResponseHandler<T> responseHandler)Handle response body with handler, return a new response with content as handler result.<T> HTTPResponse<T>handleAsInput(Function<? super InputStream,T> handler)Handle response content as InputStream.<T> HTTPResponse<T>handleAsReader(Function<? super Reader,T> handler)Handle response content as reader.HTTPResponse<byte[]>toBinaryResponse()Convert to response, with body as byte arrayHTTPResponse<String>toStringResponse()Convert to response, with body as text.HTTPResponse<Void>writeTo(OutputStream out)Write response body to OutputStream.HTTPResponse<Void>writeTo(Writer writer)Write response body to Writer, charset can be set usingcharset(Charset), or will use charset detected from response header if not set.HTTPResponse<Path>writeTo(Path path)Write response body to file
-
-
-
方法详细资料
-
charset
public HTTPResponseContext charset(Charset charset)
Set response body read charset. If not set, would get charset from response headers. If not found, would use UTF-8.- 参数:
charset- the charset used to decode response body. Cannot be null
-
autoDecompress
public HTTPResponseContext autoDecompress(boolean autoDecompress)
If decompress http response body automatically. Default True.
-
handle
public <T> HTTPResponse<T> handle(ResponseHandler<T> responseHandler)
Handle response body with handler, return a new response with content as handler result. ResponseHandler should consume all InputStream data, or connection may close and cannot reuse. The response is closed whether this call succeed or failed with exception.
-
toStringResponse
public HTTPResponse<String> toStringResponse()
Convert to response, with body as text. The origin raw response will be closed
-
toBinaryResponse
public HTTPResponse<byte[]> toBinaryResponse()
Convert to response, with body as byte array
-
writeTo
public HTTPResponse<Path> writeTo(Path path)
Write response body to file
-
writeTo
public HTTPResponse<Void> writeTo(OutputStream out)
Write response body to OutputStream. OutputStream will not be closed.
-
writeTo
public HTTPResponse<Void> writeTo(Writer writer)
Write response body to Writer, charset can be set usingcharset(Charset), or will use charset detected from response header if not set. Writer will not be closed.
-
discard
public HTTPResponse<Void> discard()
Consume and discard this response body.
-
handleAsReader
public <T> HTTPResponse<T> handleAsReader(Function<? super Reader,T> handler)
Handle response content as reader. The reader passed to handler will be closed when handler finished.- 类型参数:
T- the response body type to convert to- 参数:
handler- the handler
-
handleAsInput
public <T> HTTPResponse<T> handleAsInput(Function<? super InputStream,T> handler)
Handle response content as InputStream. The InputStream passed to handler will be closed when handler finished.- 类型参数:
T- the response body type to convert to- 参数:
handler- the handler
-
close
public void close()
- 指定者:
close在接口中AutoCloseable
-
-