モジュール java.net.http
パッケージ java.net.http

クラスHttpResponse.BodySubscribers

java.lang.Object
java.net.http.HttpResponse.BodySubscribers
含まれているインタフェース:
HttpResponse<T>

public static class HttpResponse.BodySubscribers extends Object
レスポンス本文バイトをStringに変換したり、バイトをファイルにストリーミングするなど、様々な有用なサブスクライバを実装するBodySubscriberの実装。

次に、事前定義済の本文サブスクライバを使用して、レスポンス本文データのフローを一般的な高水準のJavaオブジェクトに変換する例を示します。

// Streams the response body to a File
HttpResponse<Path> response = client
  .send(request, responseInfo -> BodySubscribers.ofFile(Paths.get("example.html"));
// Accumulates the response body and returns it as a byte[]
HttpResponse<byte[]> response = client
  .send(request, responseInfo -> BodySubscribers.ofByteArray());
// Discards the response body
HttpResponse<Void> response = client
  .send(request, responseInfo -> BodySubscribers.discarding());
// Accumulates the response body as a String then maps it to its bytes
HttpResponse<byte[]> response = client
  .send(request, responseInfo ->
     BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), String::getBytes));

導入されたバージョン:
11