src/java.net.http/share/classes/jdk/internal/net/http/LineSubscriberAdapter.java
author chegar
Sat, 24 Feb 2018 11:27:11 +0000
branchhttp-client-branch
changeset 56167 96fa4f49a9ff
parent 56159 039ab5a71a5c
child 56451 9585061fdb04
permissions -rw-r--r--
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     1
/*
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     4
 *
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    10
 *
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    15
 * accompanied this code).
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    16
 *
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    20
 *
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    23
 * questions.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    24
 */
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    25
56092
fd85b2bf2b0d http-client-branch: move implementation to jdk.internal.net.http
chegar
parents: 56089
diff changeset
    26
package jdk.internal.net.http;
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    27
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    28
import java.nio.ByteBuffer;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    29
import java.nio.CharBuffer;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    30
import java.nio.charset.CharacterCodingException;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    31
import java.nio.charset.Charset;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    32
import java.nio.charset.CharsetDecoder;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    33
import java.nio.charset.CoderResult;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    34
import java.nio.charset.CodingErrorAction;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    35
import java.util.List;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    36
import java.util.Objects;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    37
import java.util.concurrent.CompletableFuture;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    38
import java.util.concurrent.CompletionStage;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    39
import java.util.concurrent.ConcurrentLinkedDeque;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    40
import java.util.concurrent.Flow;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    41
import java.util.concurrent.Flow.Subscriber;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    42
import java.util.concurrent.Flow.Subscription;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    43
import java.util.concurrent.atomic.AtomicLong;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    44
import java.util.concurrent.atomic.AtomicReference;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    45
import java.util.function.Function;
56092
fd85b2bf2b0d http-client-branch: move implementation to jdk.internal.net.http
chegar
parents: 56089
diff changeset
    46
import jdk.internal.net.http.common.Demand;
56089
42208b2f224e http-client-branch: move to standard package and module name
chegar
parents: 56078
diff changeset
    47
import java.net.http.HttpResponse.BodySubscriber;
56092
fd85b2bf2b0d http-client-branch: move implementation to jdk.internal.net.http
chegar
parents: 56089
diff changeset
    48
import jdk.internal.net.http.common.MinimalFuture;
fd85b2bf2b0d http-client-branch: move implementation to jdk.internal.net.http
chegar
parents: 56089
diff changeset
    49
import jdk.internal.net.http.common.SequentialScheduler;
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    50
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    51
/** An adapter between {@code BodySubscriber} and {@code Flow.Subscriber<String>}. */
56078
6c11b48a0695 http-client-branch: move LineSubscriberAdapter to internal
chegar
parents: 56009
diff changeset
    52
public final class LineSubscriberAdapter<S extends Subscriber<? super String>,R>
6c11b48a0695 http-client-branch: move LineSubscriberAdapter to internal
chegar
parents: 56009
diff changeset
    53
        implements BodySubscriber<R> {
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    54
    private final CompletableFuture<R> cf = new MinimalFuture<>();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    55
    private final S subscriber;
56159
039ab5a71a5c http-client-branch: type paramater review of generic methods
chegar
parents: 56101
diff changeset
    56
    private final Function<? super S, ? extends R> finisher;
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    57
    private final Charset charset;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    58
    private final String eol;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    59
    private volatile LineSubscription downstream;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    60
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    61
    private LineSubscriberAdapter(S subscriber,
56159
039ab5a71a5c http-client-branch: type paramater review of generic methods
chegar
parents: 56101
diff changeset
    62
                                  Function<? super S, ? extends R> finisher,
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    63
                                  Charset charset,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    64
                                  String eol) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    65
        if (eol != null && eol.isEmpty())
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    66
            throw new IllegalArgumentException("empty line separator");
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    67
        this.subscriber = Objects.requireNonNull(subscriber);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    68
        this.finisher = Objects.requireNonNull(finisher);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    69
        this.charset = Objects.requireNonNull(charset);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    70
        this.eol = eol;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    71
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    72
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    73
    @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    74
    public void onSubscribe(Subscription subscription) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    75
        downstream = LineSubscription.create(subscription,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    76
                                             charset,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    77
                                             eol,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    78
                                             subscriber,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    79
                                             cf);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    80
        subscriber.onSubscribe(downstream);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    81
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    82
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    83
    @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    84
    public void onNext(List<ByteBuffer> item) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    85
        try {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    86
            downstream.submit(item);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    87
        } catch (Throwable t) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    88
            onError(t);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    89
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    90
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    91
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    92
    @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    93
    public void onError(Throwable throwable) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    94
        try {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    95
            downstream.signalError(throwable);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    96
        } finally {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    97
            cf.completeExceptionally(throwable);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    98
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
    99
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   100
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   101
    @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   102
    public void onComplete() {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   103
        try {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   104
            downstream.signalComplete();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   105
        } finally {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   106
            cf.complete(finisher.apply(subscriber));
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   107
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   108
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   109
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   110
    @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   111
    public CompletionStage<R> getBody() {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   112
        return cf;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   113
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   114
56078
6c11b48a0695 http-client-branch: move LineSubscriberAdapter to internal
chegar
parents: 56009
diff changeset
   115
    public static <S extends Subscriber<? super String>, R> LineSubscriberAdapter<S, R>
56159
039ab5a71a5c http-client-branch: type paramater review of generic methods
chegar
parents: 56101
diff changeset
   116
    create(S subscriber, Function<? super S, ? extends R> finisher, Charset charset, String eol)
56009
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   117
    {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   118
        if (eol != null && eol.isEmpty())
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   119
            throw new IllegalArgumentException("empty line separator");
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   120
        return new LineSubscriberAdapter<>(Objects.requireNonNull(subscriber),
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   121
                Objects.requireNonNull(finisher),
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   122
                Objects.requireNonNull(charset),
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   123
                eol);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   124
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   125
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   126
    static final class LineSubscription implements Flow.Subscription {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   127
        final Flow.Subscription upstreamSubscription;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   128
        final CharsetDecoder decoder;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   129
        final String newline;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   130
        final Demand downstreamDemand;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   131
        final ConcurrentLinkedDeque<ByteBuffer> queue;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   132
        final SequentialScheduler scheduler;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   133
        final Flow.Subscriber<? super String> upstream;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   134
        final CompletableFuture<?> cf;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   135
        private final AtomicReference<Throwable> errorRef = new AtomicReference<>();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   136
        private final AtomicLong demanded = new AtomicLong();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   137
        private volatile boolean completed;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   138
        private volatile boolean cancelled;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   139
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   140
        private final char[] chars = new char[1024];
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   141
        private final ByteBuffer leftover = ByteBuffer.wrap(new byte[64]);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   142
        private final CharBuffer buffer = CharBuffer.wrap(chars);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   143
        private final StringBuilder builder = new StringBuilder();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   144
        private String nextLine;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   145
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   146
        private LineSubscription(Flow.Subscription s,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   147
                                 CharsetDecoder dec,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   148
                                 String separator,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   149
                                 Flow.Subscriber<? super String> subscriber,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   150
                                 CompletableFuture<?> completion) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   151
            downstreamDemand = new Demand();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   152
            queue = new ConcurrentLinkedDeque<>();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   153
            upstreamSubscription = Objects.requireNonNull(s);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   154
            decoder = Objects.requireNonNull(dec);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   155
            newline = separator;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   156
            upstream = Objects.requireNonNull(subscriber);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   157
            cf = Objects.requireNonNull(completion);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   158
            scheduler = SequentialScheduler.synchronizedScheduler(this::loop);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   159
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   160
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   161
        @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   162
        public void request(long n) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   163
            if (cancelled) return;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   164
            if (downstreamDemand.increase(n)) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   165
                scheduler.runOrSchedule();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   166
            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   167
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   168
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   169
        @Override
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   170
        public void cancel() {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   171
            cancelled = true;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   172
            upstreamSubscription.cancel();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   173
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   174
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   175
        public void submit(List<ByteBuffer> list) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   176
            queue.addAll(list);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   177
            demanded.decrementAndGet();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   178
            scheduler.runOrSchedule();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   179
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   180
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   181
        public void signalComplete() {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   182
            completed = true;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   183
            scheduler.runOrSchedule();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   184
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   185
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   186
        public void signalError(Throwable error) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   187
            if (errorRef.compareAndSet(null,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   188
                    Objects.requireNonNull(error))) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   189
                scheduler.runOrSchedule();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   190
            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   191
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   192
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   193
        // This method looks at whether some bytes where left over (in leftover)
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   194
        // from decoding the previous buffer when the previous buffer was in
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   195
        // underflow. If so, it takes bytes one by one from the new buffer 'in'
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   196
        // and combines them with the leftover bytes until 'in' is exhausted or a
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   197
        // character was produced in 'out', resolving the previous underflow.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   198
        // Returns true if the buffer is still in underflow, false otherwise.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   199
        // However, in both situation some chars might have been produced in 'out'.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   200
        private boolean isUnderFlow(ByteBuffer in, CharBuffer out, boolean endOfInput)
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   201
                throws CharacterCodingException {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   202
            int limit = leftover.position();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   203
            if (limit == 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   204
                // no leftover
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   205
                return false;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   206
            } else {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   207
                CoderResult res = null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   208
                while (in.hasRemaining()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   209
                    leftover.position(limit);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   210
                    leftover.limit(++limit);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   211
                    leftover.put(in.get());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   212
                    leftover.position(0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   213
                    res = decoder.decode(leftover, out,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   214
                            endOfInput && !in.hasRemaining());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   215
                    int remaining = leftover.remaining();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   216
                    if (remaining > 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   217
                        assert leftover.position() == 0;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   218
                        leftover.position(remaining);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   219
                    } else {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   220
                        leftover.position(0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   221
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   222
                    leftover.limit(leftover.capacity());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   223
                    if (res.isUnderflow() && remaining > 0 && in.hasRemaining()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   224
                        continue;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   225
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   226
                    if (res.isError()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   227
                        res.throwException();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   228
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   229
                    assert !res.isOverflow();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   230
                    return false;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   231
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   232
                return !endOfInput;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   233
            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   234
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   235
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   236
        // extract characters from start to end and remove them from
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   237
        // the StringBuilder
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   238
        private static String take(StringBuilder b, int start, int end) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   239
            assert start == 0;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   240
            String line;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   241
            if (end == start) return "";
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   242
            line = b.substring(start, end);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   243
            b.delete(start, end);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   244
            return line;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   245
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   246
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   247
        // finds end of line, returns -1 if not found, or the position after
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   248
        // the line delimiter if found, removing the delimiter in the process.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   249
        private static int endOfLine(StringBuilder b, String eol, boolean endOfInput) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   250
            int len = b.length();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   251
            if (eol != null) { // delimiter explicitly specified
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   252
                int i = b.indexOf(eol);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   253
                if (i >= 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   254
                    // remove the delimiter and returns the position
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   255
                    // of the char after it.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   256
                    b.delete(i, i + eol.length());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   257
                    return i;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   258
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   259
            } else { // no delimiter specified, behaves as BufferedReader::readLine
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   260
                boolean crfound = false;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   261
                for (int i = 0; i < len; i++) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   262
                    char c = b.charAt(i);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   263
                    if (c == '\n') {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   264
                        // '\n' or '\r\n' found.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   265
                        // remove the delimiter and returns the position
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   266
                        // of the char after it.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   267
                        b.delete(crfound ? i - 1 : i, i + 1);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   268
                        return crfound ? i - 1 : i;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   269
                    } else if (crfound) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   270
                        // previous char was '\r', c != '\n'
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   271
                        assert i != 0;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   272
                        // remove the delimiter and returns the position
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   273
                        // of the char after it.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   274
                        b.delete(i - 1, i);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   275
                        return i - 1;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   276
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   277
                    crfound = c == '\r';
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   278
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   279
                if (crfound && endOfInput) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   280
                    // remove the delimiter and returns the position
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   281
                    // of the char after it.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   282
                    b.delete(len - 1, len);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   283
                    return len - 1;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   284
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   285
            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   286
            return endOfInput && len > 0 ? len : -1;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   287
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   288
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   289
        // Looks at whether the StringBuilder contains a line.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   290
        // Returns null if more character are needed.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   291
        private static String nextLine(StringBuilder b, String eol, boolean endOfInput) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   292
            int next = endOfLine(b, eol, endOfInput);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   293
            return (next > -1) ? take(b, 0, next) : null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   294
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   295
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   296
        // Attempts to read the next line. Returns the next line if
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   297
        // the delimiter was found, null otherwise. The delimiters are
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   298
        // consumed.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   299
        private String nextLine()
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   300
                throws CharacterCodingException {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   301
            assert nextLine == null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   302
            LINES:
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   303
            while (nextLine == null) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   304
                boolean endOfInput = completed && queue.isEmpty();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   305
                nextLine = nextLine(builder, newline,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   306
                        endOfInput && leftover.position() == 0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   307
                if (nextLine != null) return nextLine;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   308
                ByteBuffer b;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   309
                BUFFERS:
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   310
                while ((b = queue.peek()) != null) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   311
                    if (!b.hasRemaining()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   312
                        queue.poll();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   313
                        continue BUFFERS;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   314
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   315
                    BYTES:
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   316
                    while (b.hasRemaining()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   317
                        buffer.position(0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   318
                        buffer.limit(buffer.capacity());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   319
                        boolean endofInput = completed && queue.size() <= 1;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   320
                        if (isUnderFlow(b, buffer, endofInput)) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   321
                            assert !b.hasRemaining();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   322
                            if (buffer.position() > 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   323
                                buffer.flip();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   324
                                builder.append(buffer);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   325
                            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   326
                            continue BUFFERS;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   327
                        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   328
                        CoderResult res = decoder.decode(b, buffer, endofInput);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   329
                        if (res.isError()) res.throwException();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   330
                        if (buffer.position() > 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   331
                            buffer.flip();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   332
                            builder.append(buffer);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   333
                            continue LINES;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   334
                        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   335
                        if (res.isUnderflow() && b.hasRemaining()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   336
                            //System.out.println("underflow: adding " + b.remaining() + " bytes");
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   337
                            leftover.put(b);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   338
                            assert !b.hasRemaining();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   339
                            continue BUFFERS;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   340
                        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   341
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   342
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   343
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   344
                assert queue.isEmpty();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   345
                if (endOfInput) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   346
                    // Time to cleanup: there may be some undecoded leftover bytes
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   347
                    // We need to flush them out.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   348
                    // The decoder has been configured to replace malformed/unmappable
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   349
                    // chars with some replacement, in order to behave like
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   350
                    // InputStreamReader.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   351
                    leftover.flip();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   352
                    buffer.position(0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   353
                    buffer.limit(buffer.capacity());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   354
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   355
                    // decode() must be called just before flush, even if there
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   356
                    // is nothing to decode. We must do this even if leftover
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   357
                    // has no remaining bytes.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   358
                    CoderResult res = decoder.decode(leftover, buffer, endOfInput);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   359
                    if (buffer.position() > 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   360
                        buffer.flip();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   361
                        builder.append(buffer);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   362
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   363
                    if (res.isError()) res.throwException();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   364
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   365
                    // Now call decoder.flush()
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   366
                    buffer.position(0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   367
                    buffer.limit(buffer.capacity());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   368
                    res = decoder.flush(buffer);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   369
                    if (buffer.position() > 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   370
                        buffer.flip();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   371
                        builder.append(buffer);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   372
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   373
                    if (res.isError()) res.throwException();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   374
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   375
                    // It's possible that we reach here twice - just for the
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   376
                    // purpose of checking that no bytes were left over, so
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   377
                    // we reset leftover/decoder to make the function reentrant.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   378
                    leftover.position(0);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   379
                    leftover.limit(leftover.capacity());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   380
                    decoder.reset();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   381
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   382
                    // if some chars were produced then this call will
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   383
                    // return them.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   384
                    return nextLine = nextLine(builder, newline, endOfInput);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   385
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   386
                return null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   387
            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   388
            return null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   389
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   390
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   391
        // The main sequential scheduler loop.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   392
        private void loop() {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   393
            try {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   394
                while (!cancelled) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   395
                    Throwable error = errorRef.get();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   396
                    if (error != null) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   397
                        cancelled = true;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   398
                        scheduler.stop();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   399
                        upstream.onError(error);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   400
                        cf.completeExceptionally(error);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   401
                        return;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   402
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   403
                    if (nextLine == null) nextLine = nextLine();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   404
                    if (nextLine == null) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   405
                        if (completed) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   406
                            scheduler.stop();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   407
                            if (leftover.position() != 0) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   408
                                // Underflow: not all bytes could be
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   409
                                // decoded, but no more bytes will be coming.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   410
                                // This should not happen as we should already
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   411
                                // have got a MalformedInputException, or
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   412
                                // replaced the unmappable chars.
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   413
                                errorRef.compareAndSet(null,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   414
                                        new IllegalStateException(
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   415
                                                "premature end of input ("
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   416
                                                        + leftover.position()
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   417
                                                        + " undecoded bytes)"));
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   418
                                continue;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   419
                            } else {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   420
                                upstream.onComplete();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   421
                            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   422
                            return;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   423
                        } else if (demanded.get() == 0
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   424
                                && !downstreamDemand.isFulfilled()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   425
                            long incr = Math.max(1, downstreamDemand.get());
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   426
                            demanded.addAndGet(incr);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   427
                            upstreamSubscription.request(incr);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   428
                            continue;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   429
                        } else return;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   430
                    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   431
                    assert nextLine != null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   432
                    assert newline != null && !nextLine.endsWith(newline)
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   433
                            || !nextLine.endsWith("\n") || !nextLine.endsWith("\r");
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   434
                    if (downstreamDemand.tryDecrement()) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   435
                        String forward = nextLine;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   436
                        nextLine = null;
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   437
                        upstream.onNext(forward);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   438
                    } else return; // no demand: come back later
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   439
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   440
            } catch (Throwable t) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   441
                try {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   442
                    upstreamSubscription.cancel();
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   443
                } finally {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   444
                    signalError(t);
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   445
                }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   446
            }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   447
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   448
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   449
        static LineSubscription create(Flow.Subscription s,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   450
                                       Charset charset,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   451
                                       String lineSeparator,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   452
                                       Flow.Subscriber<? super String> upstream,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   453
                                       CompletableFuture<?> cf) {
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   454
            return new LineSubscription(Objects.requireNonNull(s),
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   455
                    Objects.requireNonNull(charset).newDecoder()
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   456
                            // use the same decoder configuration than
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   457
                            // java.io.InputStreamReader
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   458
                            .onMalformedInput(CodingErrorAction.REPLACE)
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   459
                            .onUnmappableCharacter(CodingErrorAction.REPLACE),
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   460
                    lineSeparator,
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   461
                    Objects.requireNonNull(upstream),
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   462
                    Objects.requireNonNull(cf));
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   463
        }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   464
    }
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   465
}
cf8792f51dee http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
diff changeset
   466