Browse Source

Implement review feedback.

Remove empty string optimization. Simplify test to use only Mono/Flux/TestSubscriber instead of mixing with RxJava.
pull/1111/head
Mark Paluch 10 years ago
parent
commit
9e79b344ca
  1. 6
      spring-web-reactive/src/main/java/org/springframework/core/codec/support/StringDecoder.java
  2. 11
      spring-web-reactive/src/test/java/org/springframework/core/codec/support/StringDecoderTests.java

6
spring-web-reactive/src/main/java/org/springframework/core/codec/support/StringDecoder.java

@ -45,7 +45,6 @@ import org.springframework.util.MimeType; @@ -45,7 +45,6 @@ import org.springframework.util.MimeType;
public class StringDecoder extends AbstractDecoder<String> {
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
public static final String EMPTY = "";
private final boolean reduceToSingleBuffer;
@ -85,11 +84,6 @@ public class StringDecoder extends AbstractDecoder<String> { @@ -85,11 +84,6 @@ public class StringDecoder extends AbstractDecoder<String> {
}
Charset charset = getCharset(mimeType);
return inputFlux.map(content -> {
// fast-path exit.
if(content.readableByteCount() == 0) {
return EMPTY;
}
CharBuffer charBuffer = charset.decode(content.asByteBuffer());
return charBuffer.toString();
});

11
spring-web-reactive/src/test/java/org/springframework/core/codec/support/StringDecoderTests.java

@ -95,12 +95,11 @@ public class StringDecoderTests extends AbstractAllocatingTestCase { @@ -95,12 +95,11 @@ public class StringDecoderTests extends AbstractAllocatingTestCase {
@Test
public void decodeEmpty() throws InterruptedException {
Flux<DataBuffer> source = Flux.just(stringBuffer(""));
Single<String> single = RxJava1SingleConverter.from(this.decoder.decode(source,
ResolvableType.forClassWithGenerics(Single.class, String.class),
MediaType.TEXT_PLAIN));
String result = single.toBlocking().value();
assertEquals("", result);
Mono<DataBuffer> source = Mono.just(stringBuffer(""));
Flux<String> output =
this.decoder.decode(source, ResolvableType.forClass(String.class), null);
TestSubscriber<String> testSubscriber = new TestSubscriber<>();
testSubscriber.bindTo(output).assertValues("");
}
}

Loading…
Cancel
Save