< prev index next >

src/java.net.http/share/classes/java/net/http/HttpResponse.java

Print this page




1236          * @param <U> the type of the response body
1237          * @param value the value to return from HttpResponse.body(), may be {@code null}
1238          * @return a {@code BodySubscriber}
1239          */
1240         public static <U> BodySubscriber<U> replacing(U value) {
1241             return new ResponseSubscribers.NullSubscriber<>(Optional.ofNullable(value));
1242         }
1243 
1244         /**
1245          * Returns a response subscriber which discards the response body.
1246          *
1247          * @return a response body subscriber
1248          */
1249         public static BodySubscriber<Void> discarding() {
1250             return new ResponseSubscribers.NullSubscriber<>(Optional.ofNullable(null));
1251         }
1252 
1253         /**
1254          * Returns a {@code BodySubscriber} which buffers data before delivering
1255          * it to the given downstream subscriber. The subscriber guarantees to
1256          * deliver {@code bufferSize} bytes of data to each invocation of the
1257          * downstream's {@link BodySubscriber#onNext(Object) onNext} method,
1258          * except for the final invocation, just before
1259          * {@link BodySubscriber#onComplete() onComplete} is invoked. The final
1260          * invocation of {@code onNext} may contain fewer than {@code bufferSize}
1261          * bytes.
1262          *
1263          * <p> The returned subscriber delegates its {@link BodySubscriber#getBody()
1264          * getBody()} method to the downstream subscriber.
1265          *
1266          * @param <T> the type of the response body
1267          * @param downstream the downstream subscriber
1268          * @param bufferSize the buffer size
1269          * @return a buffering body subscriber
1270          * @throws IllegalArgumentException if {@code bufferSize <= 0}
1271          */
1272          public static <T> BodySubscriber<T> buffering(BodySubscriber<T> downstream,
1273                                                        int bufferSize) {
1274              if (bufferSize <= 0)
1275                  throw new IllegalArgumentException("must be greater than 0");
1276              return new BufferingSubscriber<>(downstream, bufferSize);




1236          * @param <U> the type of the response body
1237          * @param value the value to return from HttpResponse.body(), may be {@code null}
1238          * @return a {@code BodySubscriber}
1239          */
1240         public static <U> BodySubscriber<U> replacing(U value) {
1241             return new ResponseSubscribers.NullSubscriber<>(Optional.ofNullable(value));
1242         }
1243 
1244         /**
1245          * Returns a response subscriber which discards the response body.
1246          *
1247          * @return a response body subscriber
1248          */
1249         public static BodySubscriber<Void> discarding() {
1250             return new ResponseSubscribers.NullSubscriber<>(Optional.ofNullable(null));
1251         }
1252 
1253         /**
1254          * Returns a {@code BodySubscriber} which buffers data before delivering
1255          * it to the given downstream subscriber. The subscriber guarantees to
1256          * deliver {@code buffersize} bytes of data to each invocation of the
1257          * downstream's {@link BodySubscriber#onNext(Object) onNext} method,
1258          * except for the final invocation, just before
1259          * {@link BodySubscriber#onComplete() onComplete} is invoked. The final
1260          * invocation of {@code onNext} may contain fewer than {@code bufferSize}
1261          * bytes.
1262          *
1263          * <p> The returned subscriber delegates its {@link BodySubscriber#getBody()
1264          * getBody()} method to the downstream subscriber.
1265          *
1266          * @param <T> the type of the response body
1267          * @param downstream the downstream subscriber
1268          * @param bufferSize the buffer size
1269          * @return a buffering body subscriber
1270          * @throws IllegalArgumentException if {@code bufferSize <= 0}
1271          */
1272          public static <T> BodySubscriber<T> buffering(BodySubscriber<T> downstream,
1273                                                        int bufferSize) {
1274              if (bufferSize <= 0)
1275                  throw new IllegalArgumentException("must be greater than 0");
1276              return new BufferingSubscriber<>(downstream, bufferSize);


< prev index next >