11/*
2- * Copyright 2002-2019 the original author or authors.
2+ * Copyright 2002-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2929import org .springframework .core .codec .Encoder ;
3030import org .springframework .core .codec .Hints ;
3131import org .springframework .core .io .buffer .DataBuffer ;
32+ import org .springframework .core .io .buffer .DataBufferUtils ;
3233import org .springframework .core .io .buffer .PooledDataBuffer ;
33- import org .springframework .http .HttpHeaders ;
3434import org .springframework .http .HttpLogging ;
3535import org .springframework .http .MediaType ;
3636import org .springframework .http .ReactiveHttpOutputMessage ;
@@ -108,7 +108,6 @@ public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaTyp
108108 return this .encoder .canEncode (elementType , mediaType );
109109 }
110110
111- @ SuppressWarnings ("unchecked" )
112111 @ Override
113112 public Mono <Void > write (Publisher <? extends T > inputStream , ResolvableType elementType ,
114113 @ Nullable MediaType mediaType , ReactiveHttpOutputMessage message , Map <String , Object > hints ) {
@@ -119,23 +118,23 @@ public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType eleme
119118 inputStream , message .bufferFactory (), elementType , contentType , hints );
120119
121120 if (inputStream instanceof Mono ) {
122- HttpHeaders headers = message .getHeaders ();
123121 return body
124122 .singleOrEmpty ()
125123 .switchIfEmpty (Mono .defer (() -> {
126- headers .setContentLength (0 );
124+ message . getHeaders () .setContentLength (0 );
127125 return message .setComplete ().then (Mono .empty ());
128126 }))
129127 .flatMap (buffer -> {
130- headers .setContentLength (buffer .readableByteCount ());
128+ message . getHeaders () .setContentLength (buffer .readableByteCount ());
131129 return message .writeWith (Mono .just (buffer )
132- .doOnDiscard (PooledDataBuffer .class , PooledDataBuffer ::release ));
133- });
130+ .doOnDiscard (PooledDataBuffer .class , DataBufferUtils ::release ));
131+ })
132+ .doOnDiscard (PooledDataBuffer .class , DataBufferUtils ::release );
134133 }
135134
136135 if (isStreamingMediaType (contentType )) {
137136 return message .writeAndFlushWith (body .map (buffer ->
138- Mono .just (buffer ).doOnDiscard (PooledDataBuffer .class , PooledDataBuffer ::release )));
137+ Mono .just (buffer ).doOnDiscard (PooledDataBuffer .class , DataBufferUtils ::release )));
139138 }
140139
141140 return message .writeWith (body );
0 commit comments