http-client-branch: fix javadoc examples in BodySubscribers http-client-branch
authorchegar
Fri, 01 Jun 2018 17:15:58 +0100
branchhttp-client-branch
changeset 56653 e9009db09cff
parent 56652 8e00f02b7dfc
child 56654 b72e5af6fb6b
http-client-branch: fix javadoc examples in BodySubscribers
src/java.net.http/share/classes/java/net/http/HttpResponse.java
test/jdk/java/net/httpclient/examples/JavadocExamples.java
--- a/src/java.net.http/share/classes/java/net/http/HttpResponse.java	Fri Jun 01 16:43:54 2018 +0100
+++ b/src/java.net.http/share/classes/java/net/http/HttpResponse.java	Fri Jun 01 17:15:58 2018 +0100
@@ -888,20 +888,20 @@
      *
      * <pre>{@code    // Streams the response body to a File
      *   HttpResponse<byte[]> response = client
-     *     .send(request, (statusCode, responseHeaders) -> BodySubscribers.ofByteArray());
+     *     .send(request, responseInfo -> BodySubscribers.ofByteArray());
      *
      *   // Accumulates the response body and returns it as a byte[]
      *   HttpResponse<byte[]> response = client
-     *     .send(request, (statusCode, responseHeaders) -> BodySubscribers.ofByteArray());
+     *     .send(request, responseInfo -> BodySubscribers.ofByteArray());
      *
      *   // Discards the response body
      *   HttpResponse<Void> response = client
-     *     .send(request, (statusCode, responseHeaders) -> BodySubscribers.discarding());
+     *     .send(request, responseInfo -> BodySubscribers.discarding());
      *
      *   // Accumulates the response body as a String then maps it to its bytes
      *   HttpResponse<byte[]> response = client
-     *     .send(request, (sc, hdrs) ->
-     *        BodySubscribers.mapping(BodySubscribers.ofString(), String::getBytes));
+     *     .send(request, responseInfo ->
+     *        BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), String::getBytes));
      * }</pre>
      *
      * @since 11
--- a/test/jdk/java/net/httpclient/examples/JavadocExamples.java	Fri Jun 01 16:43:54 2018 +0100
+++ b/test/jdk/java/net/httpclient/examples/JavadocExamples.java	Fri Jun 01 17:15:58 2018 +0100
@@ -45,6 +45,7 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Flow;
 import java.util.regex.Pattern;
+import static java.nio.charset.StandardCharsets.UTF_8;
 
 /*
  * THE CONTENTS OF THIS FILE HAVE TO BE IN SYNC WITH THE EXAMPLES USED IN THE
@@ -156,6 +157,25 @@
         HttpResponse<Void> respons4 = client
                 .send(request, BodyHandlers.discarding());
 
+
+        // HttpResponse.BodySubscribers class-level description
+        // Streams the response body to a File
+        HttpResponse<byte[]> response5 = client
+                .send(request, responseInfo -> BodySubscribers.ofByteArray());
+
+        // Accumulates the response body and returns it as a byte[]
+        HttpResponse<byte[]> response6 = client
+                .send(request, responseInfo -> BodySubscribers.ofByteArray());
+
+        // Discards the response body
+        HttpResponse<Void> response7 = client
+                .send(request, responseInfo -> BodySubscribers.discarding());
+
+        // Accumulates the response body as a String then maps it to its bytes
+        HttpResponse<byte[]> response8 = client
+                .send(request, responseInfo ->
+                        BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), String::getBytes));
+
     }
 
     /**