Top Description Inners Fields Constructors Methods
jdk.internal.net.http

public final Class LineSubscriberAdapter<S extends Flow.Subscriber<? super String>, R>

extends Object
implements HttpResponse.BodySubscriber<R>
Class Inheritance
All Implemented Interfaces
java.net.http.HttpResponse.BodySubscriber, java.util.concurrent.Flow.Subscriber
Imports
java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharacterCodingException, .Charset, .CharsetDecoder, .CoderResult, .CodingErrorAction, java.util.List, .Objects, java.util.concurrent.CompletableFuture, .CompletionStage, .ConcurrentLinkedDeque, .Flow, .Flow.Subscriber, .Flow.Subscription, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, java.util.function.Function, jdk.internal.net.http.common.Demand, .MinimalFuture, .SequentialScheduler, java.net.http.HttpResponse.BodySubscriber

An adapter between BodySubscriber and Flow.Subscriber<String>.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final CompletableFuture<R>
private final Charset
private volatile LineSubscriberAdapter.LineSubscription
private final String
private final Function<? super S, ? extends R>
private final AtomicBoolean
private final S

Constructor Summary

AccessConstructor and Description
private
LineSubscriberAdapter(S subscriber, Function<? super S, ? extends R> finisher, Charset charset, String eol)

Method Summary

Modifier and TypeMethod and Description
public static <S extends Flow.Subscriber<? super String>, R> LineSubscriberAdapter<S, R>
create(S subscriber, Function<? super S, ? extends R> finisher, Charset charset, String eol)

public CompletionStage<R>
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
the exception
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>
the item
item
)

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

Method invoked with a Subscription's next item.
public void
onSubscribe(Flow.Subscription
a new 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

cfback to summary
private final CompletableFuture<R> cf
charsetback to summary
private final Charset charset
downstreamback to summary
private volatile LineSubscriberAdapter.LineSubscription downstream
eolback to summary
private final String eol
finisherback to summary
private final Function<? super S, ? extends R> finisher
subscribedback to summary
private final AtomicBoolean subscribed
subscriberback to summary
private final S subscriber

Constructor Detail

LineSubscriberAdapterback to summary
private LineSubscriberAdapter(S subscriber, Function<? super S, ? extends R> finisher, Charset charset, String eol)

Method Detail

createback to summary
public static <S extends Flow.Subscriber<? super String>, R> LineSubscriberAdapter<S, R> create(S subscriber, Function<? super S, ? extends R> finisher, Charset charset, String eol)
getBodyback to summary
public CompletionStage<R> 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.

Returns:CompletionStage<R>

a CompletionStage for the response body

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.

Parameters
throwable:Throwable

the exception

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

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.

Parameters
item:List<ByteBuffer>

the item

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.

Parameters
subscription:Flow.Subscription

a new subscription

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

pack-priv final Class LineSubscriberAdapter.LineSubscription

extends Object
implements Subscription
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Flow.Subscription

Field Summary

Modifier and TypeField and Description
private final CharBuffer
private final StringBuilder
private volatile boolean
pack-priv final CompletableFuture<?>
private final char[]
private volatile boolean
pack-priv final CharsetDecoder
private final AtomicLong
pack-priv final Demand
private final AtomicReference<Throwable>
private final ByteBuffer
pack-priv final String
private String
pack-priv final ConcurrentLinkedDeque<ByteBuffer>
pack-priv final SequentialScheduler
pack-priv final Flow.Subscriber<? super String>
pack-priv final Flow.Subscription

Constructor Summary

AccessConstructor and Description
private
LineSubscription(Flow.Subscription s, CharsetDecoder dec, String separator, Flow.Subscriber<? super String> subscriber, CompletableFuture<?> completion)

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages.
pack-priv static LineSubscriberAdapter.LineSubscription
create(Flow.Subscription s, Charset charset, String lineSeparator, Flow.Subscriber<? super String> upstream, CompletableFuture<?> cf)

private static int
endOfLine(StringBuilder b, String eol, boolean endOfInput)

private boolean
isUnderFlow(ByteBuffer in, CharBuffer out, boolean endOfInput)

private void
loop()

private static String
nextLine(StringBuilder b, String eol, boolean endOfInput)

private String
public void
request(long
the increment of demand; a value of Long.MAX_VALUE may be considered as effectively unbounded
n
)

Implements java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription.
public void
public void
public void
private static String
take(StringBuilder b, int start, int end)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private final CharBuffer buffer
builderback to summary
private final StringBuilder builder
cancelledback to summary
private volatile boolean cancelled
cfback to summary
pack-priv final CompletableFuture<?> cf
charsback to summary
private final char[] chars
completedback to summary
private volatile boolean completed
decoderback to summary
pack-priv final CharsetDecoder decoder
demandedback to summary
private final AtomicLong demanded
downstreamDemandback to summary
pack-priv final Demand downstreamDemand
errorRefback to summary
private final AtomicReference<Throwable> errorRef
leftoverback to summary
private final ByteBuffer leftover
newlineback to summary
pack-priv final String newline
nextLineback to summary
private String nextLine
queueback to summary
pack-priv final ConcurrentLinkedDeque<ByteBuffer> queue
schedulerback to summary
pack-priv final SequentialScheduler scheduler
upstreamback to summary
pack-priv final Flow.Subscriber<? super String> upstream
upstreamSubscriptionback to summary
pack-priv final Flow.Subscription upstreamSubscription

Constructor Detail

LineSubscriptionback to summary
private LineSubscription(Flow.Subscription s, CharsetDecoder dec, String separator, Flow.Subscriber<? super String> subscriber, CompletableFuture<?> completion)

Method Detail

cancelback to summary
public void cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Doc from java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an onComplete or onError signal.

Annotations
@Override
createback to summary
pack-priv static LineSubscriberAdapter.LineSubscription create(Flow.Subscription s, Charset charset, String lineSeparator, Flow.Subscriber<? super String> upstream, CompletableFuture<?> cf)
endOfLineback to summary
private static int endOfLine(StringBuilder b, String eol, boolean endOfInput)
isUnderFlowback to summary
private boolean isUnderFlow(ByteBuffer in, CharBuffer out, boolean endOfInput) throws CharacterCodingException
loopback to summary
private void loop()
nextLineback to summary
private static String nextLine(StringBuilder b, String eol, boolean endOfInput)
nextLineback to summary
private String nextLine() throws CharacterCodingException
requestback to summary
public void request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Doc from java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription. If n is less than or equal to zero, the Subscriber will receive an onError signal with an IllegalArgumentException argument. Otherwise, the Subscriber will receive up to n additional onNext invocations (or fewer if terminated).

Parameters
n:long

the increment of demand; a value of Long.MAX_VALUE may be considered as effectively unbounded

Annotations
@Override
signalCompleteback to summary
public void signalComplete()
signalErrorback to summary
public void signalError(Throwable error)
submitback to summary
public void submit(List<ByteBuffer> list)
takeback to summary
private static String take(StringBuilder b, int start, int end)