APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http

public final Class LimitingSubscriber<T>

extends Object
implements ResponseSubscribers.TrustedSubscriber<T>
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber, java.net.http.HttpResponse.BodySubscriber, java.util.concurrent.Flow.Subscriber
Type Parameters
<T>
the response type
Imports
jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber, jdk.internal.net.http.common.Utils, java.io.IOException, java.net.http.HttpResponse.BodySubscriber, java.nio.ByteBuffer, java.util.List, java.util.concurrent.CompletionStage, .Flow.Subscription

A subscriber limiting the maximum number of bytes that are allowed to be consumed by a downstream subscriber.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface

Field Summary

Modifier and TypeField and Description
private final long
private final HttpResponse.BodySubscriber<T>
private long
private LimitingSubscriber.State

Constructor Summary

AccessConstructor and Description
public
LimitingSubscriber(HttpResponse.BodySubscriber<T>
the downstream subscriber to pass received data to
downstreamSubscriber
,
long
the maximum number of bytes that are allowed
capacity
)

Method Summary

Modifier and TypeMethod and Description
private boolean
public CompletionStage<T>
getBody()

Implements java.net.http.HttpResponse.BodySubscriber.getBody.

Returns a CompletionStage which when completed will return the response body object.

public void
onComplete()

Implements java.util.concurrent.Flow.Subscriber.onComplete.

Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription.

public void
onError(Throwable throwable)

Implements java.util.concurrent.Flow.Subscriber.onError.

Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription.

public void
onNext(List<ByteBuffer> buffers)

Implements java.util.concurrent.Flow.Subscriber.onNext.

Method invoked with a Subscription's next item.

public void
onSubscribe(Flow.Subscription subscription)

Implements java.util.concurrent.Flow.Subscriber.onSubscribe.

Method invoked prior to invoking any other Subscriber methods for the given Subscription.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

capacityback to summary
private final long capacity
downstreamSubscriberback to summary
private final HttpResponse.BodySubscriber<T> downstreamSubscriber
lengthback to summary
private long length
stateback to summary
private LimitingSubscriber.State state

Constructor Detail

LimitingSubscriberback to summary
public LimitingSubscriber(HttpResponse.BodySubscriber<T> downstreamSubscriber, long capacity)
Parameters
downstreamSubscriber:HttpResponse.BodySubscriber<T>

the downstream subscriber to pass received data to

capacity:long

the maximum number of bytes that are allowed

Exceptions
IllegalArgumentException:
if capacity is negative

Method Detail

allocateLengthback to summary
private boolean allocateLength(List<ByteBuffer> buffers)
getBodyback to summary
public CompletionStage<T> getBody()

Implements java.net.http.HttpResponse.BodySubscriber.getBody.

Doc from java.net.http.HttpResponse.BodySubscriber.getBody.

Returns a CompletionStage which when completed will return the response body object. This method can be called at any time relative to the other Flow.Subscriber methods and is invoked using the client's executor.

Annotations
@Override
onCompleteback to summary
public void onComplete()

Implements java.util.concurrent.Flow.Subscriber.onComplete.

Doc from java.util.concurrent.Flow.Subscriber.onComplete.

Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. If this method throws an exception, resulting behavior is undefined.

Annotations
@Override
onErrorback to summary
public void onError(Throwable throwable)

Implements java.util.concurrent.Flow.Subscriber.onError.

Doc from java.util.concurrent.Flow.Subscriber.onError.

Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. If this method itself throws an exception, resulting behavior is undefined.

Annotations
@Override
onNextback to summary
public void onNext(List<ByteBuffer> buffers)

Implements java.util.concurrent.Flow.Subscriber.onNext.

Doc from java.util.concurrent.Flow.Subscriber.onNext.

Method invoked with a Subscription's next item. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription to be cancelled.

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Flow.Subscription subscription)

Implements java.util.concurrent.Flow.Subscriber.onSubscribe.

Doc from java.util.concurrent.Flow.Subscriber.onSubscribe.

Method invoked prior to invoking any other Subscriber methods for the given Subscription. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription not to be established or to be cancelled.

Typically, implementations of this method invoke subscription.request to enable receiving items.

Annotations
@Override
jdk.internal.net.http back to summary

private Interface LimitingSubscriber.State

Known Direct Implementers
jdk.internal.net.http.LimitingSubscriber.State.Subscribed

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static record

Field Summary

Modifier and TypeField and Description
public static final LimitingSubscriber.State

Field Detail

TERMINATEDback to summary
public static final LimitingSubscriber.State TERMINATED
jdk.internal.net.http back to summary

public final Record LimitingSubscriber.State.Subscribed

extends Record
implements State
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.LimitingSubscriber.State
Record Components
subscription:Flow.Subscription 

Field Summary

Modifier and TypeField and Description
private final Flow.Subscription
subscription

Record Component accessed by subscription().

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Flow.Subscription
subscription()

Record Component getter of subscription.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

subscriptionback to summary
private final Flow.Subscription subscription

Record Component accessed by subscription().

Constructor Detail

Subscribedback to summary
public Subscribed(Flow.Subscription subscription)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

subscriptionback to summary
public Flow.Subscription subscription()

Record Component getter of subscription.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.