- java.lang.Object
-
- net.dongliu.cute.http.AsyncResponseContext
-
public class AsyncResponseContext extends Object
Async Http Response.
-
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 AsyncResponseContextautoDecompress(boolean autoDecompress)If decompress response body automatically.<T> CompletableFuture<Response<T>>decodeJson(Class<T> type)Unmarshal response body as json.<T> CompletableFuture<Response<T>>decodeJson(Class<T> type, Charset charset)Unmarshal response body as json.<T> CompletableFuture<Response<T>>decodeJson(net.dongliu.commons.reflect.TypeInfer<T> typeInfer)Unmarshal response body as json.<T> CompletableFuture<Response<T>>decodeJson(net.dongliu.commons.reflect.TypeInfer<T> typeInfer, Charset charset)Unmarshal response body as jsonCompletableFuture<Response<Void>>discard()Discard all response body.<T> CompletableFuture<Response<T>>handle(BodySubscriberProvider<T> subscriberProvider)Handle the response, return a response future.<T,R>
CompletableFuture<Response<R>>handle(BodySubscriberProvider<T> subscriberProvider, Function<? super T,? extends R> mapper)Handle the response using a BodySubscriber, then transformed the result by the function mapper.CompletableFuture<Response<byte[]>>readToBytes()Collect the response body to byte array.CompletableFuture<Response<String>>readToString()Collect the response body as String.CompletableFuture<Response<String>>readToString(Charset charset)Collect the response body as String.CompletableFuture<Response<Path>>writeTo(Path path)Write response body to file.
-
-
-
方法详细资料
-
autoDecompress
public AsyncResponseContext autoDecompress(boolean autoDecompress)
If decompress response body automatically. Default true
-
handle
public <T> CompletableFuture<Response<T>> handle(BodySubscriberProvider<T> subscriberProvider)
Handle the response, return a response future. If any exceptions were thrown during call handler, will return a exceptional Future.- 类型参数:
T- return value type- 参数:
subscriberProvider- provide a BodySubscriber to handle the body
-
handle
public <T,R> CompletableFuture<Response<R>> handle(BodySubscriberProvider<T> subscriberProvider, Function<? super T,? extends R> mapper)
Handle the response using a BodySubscriber, then transformed the result by the function mapper. If any exceptions were thrown during call handler, will return a exceptional Future.- 类型参数:
R- return value type- 参数:
subscriberProvider- provider the BodySubscriber to handle the responsemapper- the function to convert the body get by the BodySubscriber
-
readToString
public CompletableFuture<Response<String>> readToString(Charset charset)
Collect the response body as String.- 参数:
charset- the charset used to decode response body.- 返回:
- the response Future
-
readToString
public CompletableFuture<Response<String>> readToString()
Collect the response body as String. This method would get charset from response headers. If not set, would use UTF-8.- 返回:
- the response Future
-
readToBytes
public CompletableFuture<Response<byte[]>> readToBytes()
Collect the response body to byte array.- 返回:
- the response Future
-
decodeJson
public <T> CompletableFuture<Response<T>> decodeJson(Class<T> type)
Unmarshal response body as json. This method would get charset from response headers. If not set, would use UTF-8.- 类型参数:
T- The json value type
-
decodeJson
public <T> CompletableFuture<Response<T>> decodeJson(net.dongliu.commons.reflect.TypeInfer<T> typeInfer)
Unmarshal response body as json. This method would get charset from response headers. If not set, would use UTF-8.- 类型参数:
T- The json value type- 参数:
typeInfer- for getting actual generic type
-
decodeJson
public <T> CompletableFuture<Response<T>> decodeJson(Class<T> type, Charset charset)
Unmarshal response body as json.- 类型参数:
T- The json value type- 参数:
charset- the charset used to decode response body.
-
decodeJson
public <T> CompletableFuture<Response<T>> decodeJson(net.dongliu.commons.reflect.TypeInfer<T> typeInfer, Charset charset)
Unmarshal response body as json- 类型参数:
T- The json value type- 参数:
charset- the charset used to decode response body.typeInfer- for getting actual generic type
-
discard
public CompletableFuture<Response<Void>> discard()
Discard all response body.- 返回:
- the response Future
-
writeTo
public CompletableFuture<Response<Path>> writeTo(Path path)
Write response body to file.- 参数:
path- the file path- 返回:
- the response future
-
-