Skip to content

Commit 113b430

Browse files
committed
Align OutputStreamPublisher's
Apply recent nullability changes, and formatting differences. See gh-33592
1 parent a1613d1 commit 113b430

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
5454
private final int chunkSize;
5555

5656

57-
OutputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory,
57+
OutputStreamPublisher(
58+
Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory,
5859
Executor executor, int chunkSize) {
5960

6061
this.outputStreamConsumer = outputStreamConsumer;
@@ -99,8 +100,9 @@ private static final class OutputStreamSubscription extends OutputStream impleme
99100

100101
private long produced;
101102

102-
OutputStreamSubscription(Subscriber<? super DataBuffer> actual,
103-
Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) {
103+
OutputStreamSubscription(
104+
Subscriber<? super DataBuffer> actual, Consumer<OutputStream> outputStreamConsumer,
105+
DataBufferFactory bufferFactory, int chunkSize) {
104106

105107
this.actual = actual;
106108
this.outputStreamHandler = outputStreamConsumer;

spring-web/src/main/java/org/springframework/http/client/OutputStreamPublisher.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ final class OutputStreamPublisher<T> implements Flow.Publisher<T> {
5656
private final int chunkSize;
5757

5858

59-
private OutputStreamPublisher(OutputStreamHandler outputStreamHandler, ByteMapper<T> byteMapper, Executor executor, int chunkSize) {
59+
private OutputStreamPublisher(
60+
OutputStreamHandler outputStreamHandler, ByteMapper<T> byteMapper,
61+
Executor executor, int chunkSize) {
62+
6063
this.outputStreamHandler = outputStreamHandler;
6164
this.byteMapper = byteMapper;
6265
this.executor = executor;
@@ -154,8 +157,9 @@ public void subscribe(Flow.Subscriber<? super T> subscriber) {
154157
// for Reactive Streams compliance.
155158
Objects.requireNonNull(subscriber, "Subscriber must not be null");
156159

157-
OutputStreamSubscription<T> subscription = new OutputStreamSubscription<>(subscriber, this.outputStreamHandler,
158-
this.byteMapper, this.chunkSize);
160+
OutputStreamSubscription<T> subscription = new OutputStreamSubscription<>(
161+
subscriber, this.outputStreamHandler, this.byteMapper, this.chunkSize);
162+
159163
subscriber.onSubscribe(subscription);
160164
this.executor.execute(subscription::invokeHandler);
161165
}
@@ -218,7 +222,6 @@ private static final class OutputStreamSubscription<T> extends OutputStream impl
218222

219223
static final Object READY = new Object();
220224

221-
222225
private final Flow.Subscriber<? super T> actual;
223226

224227
private final OutputStreamHandler outputStreamHandler;
@@ -236,12 +239,13 @@ private static final class OutputStreamSubscription<T> extends OutputStream impl
236239

237240
private long produced;
238241

239-
240-
public OutputStreamSubscription(Flow.Subscriber<? super T> actual, OutputStreamHandler outputStreamHandler,
242+
OutputStreamSubscription(
243+
Flow.Subscriber<? super T> actual, OutputStreamHandler outputStreamHandler,
241244
ByteMapper<T> byteMapper, int chunkSize) {
245+
242246
this.actual = actual;
243-
this.byteMapper = byteMapper;
244247
this.outputStreamHandler = outputStreamHandler;
248+
this.byteMapper = byteMapper;
245249
this.chunkSize = chunkSize;
246250
}
247251

@@ -315,13 +319,14 @@ private void invokeHandler() {
315319
if (isCancelled(previousState)) {
316320
return;
317321
}
318-
319322
if (isTerminated(previousState)) {
320323
// failure due to illegal requestN
321-
this.actual.onError(this.error);
322-
return;
324+
Throwable error = this.error;
325+
if (error != null) {
326+
this.actual.onError(error);
327+
return;
328+
}
323329
}
324-
325330
this.actual.onError(ex);
326331
return;
327332
}
@@ -330,13 +335,14 @@ private void invokeHandler() {
330335
if (isCancelled(previousState)) {
331336
return;
332337
}
333-
334338
if (isTerminated(previousState)) {
335339
// failure due to illegal requestN
336-
this.actual.onError(this.error);
337-
return;
340+
Throwable error = this.error;
341+
if (error != null) {
342+
this.actual.onError(error);
343+
return;
344+
}
338345
}
339-
340346
this.actual.onComplete();
341347
}
342348

@@ -346,16 +352,13 @@ public void request(long n) {
346352
if (n <= 0) {
347353
this.error = new IllegalArgumentException("request should be a positive number");
348354
long previousState = tryTerminate();
349-
350355
if (isTerminated(previousState) || isCancelled(previousState)) {
351356
return;
352357
}
353-
354358
if (previousState > 0) {
355359
// error should eventually be observed and propagated
356360
return;
357361
}
358-
359362
// resume parked thread, so it can observe error and propagate it
360363
resume();
361364
return;
@@ -413,11 +416,9 @@ private void resume() {
413416
private long tryCancel() {
414417
while (true) {
415418
long r = this.requested.get();
416-
417419
if (isCancelled(r)) {
418420
return r;
419421
}
420-
421422
if (this.requested.compareAndSet(r, Long.MIN_VALUE)) {
422423
return r;
423424
}
@@ -427,11 +428,9 @@ private long tryCancel() {
427428
private long tryTerminate() {
428429
while (true) {
429430
long r = this.requested.get();
430-
431431
if (isCancelled(r) || isTerminated(r)) {
432432
return r;
433433
}
434-
435434
if (this.requested.compareAndSet(r, Long.MIN_VALUE | Long.MAX_VALUE)) {
436435
return r;
437436
}
@@ -486,4 +485,5 @@ private static long addCap(long a, long b) {
486485
return res;
487486
}
488487
}
488+
489489
}

0 commit comments

Comments
 (0)