Browse Source

Polishing

pull/2038/head
Juergen Hoeller 7 years ago
parent
commit
6d7827e36b
  1. 17
      spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
  2. 27
      spring-core/src/test/java/org/springframework/core/codec/StringDecoderTests.java
  3. 11
      spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java

17
spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java

@ -110,8 +110,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -110,8 +110,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
}
/**
* Splits the given data buffer on delimiter boundaries. The returned Flux contains a
* {@link #END_FRAME} buffer after each delimiter.
* Split the given data buffer on delimiter boundaries.
* The returned Flux contains an {@link #END_FRAME} buffer after each delimiter.
*/
private List<DataBuffer> splitOnDelimiter(DataBuffer dataBuffer, List<byte[]> delimiterBytes) {
List<DataBuffer> frames = new ArrayList<>();
@ -180,15 +180,14 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -180,15 +180,14 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
}
/**
* Checks whether the given buffer is {@link #END_FRAME}.
* Check whether the given buffer is {@link #END_FRAME}.
*/
private static boolean isEndFrame(DataBuffer dataBuffer) {
return dataBuffer == END_FRAME;
}
/**
* Joins the given list of buffers into a single buffer, also removing
* the (inserted) {@link #END_FRAME}.
* Join the given list of buffers into a single buffer.
*/
private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) {
if (!dataBuffers.isEmpty()) {
@ -229,7 +228,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -229,7 +228,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
* Create a {@code StringDecoder} for {@code "text/plain"}.
* @param ignored ignored
* @deprecated as of Spring 5.0.4, in favor of {@link #textPlainOnly()} or
* {@link #textPlainOnly(List, boolean)}.
* {@link #textPlainOnly(List, boolean)}
*/
@Deprecated
public static StringDecoder textPlainOnly(boolean ignored) {
@ -247,7 +246,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -247,7 +246,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
* Create a {@code StringDecoder} for {@code "text/plain"}.
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting
* input strings.
* input strings
*/
public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
return new StringDecoder(delimiters, stripDelimiter, new MimeType("text", "plain", DEFAULT_CHARSET));
@ -257,7 +256,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -257,7 +256,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
* Create a {@code StringDecoder} that supports all MIME types.
* @param ignored ignored
* @deprecated as of Spring 5.0.4, in favor of {@link #allMimeTypes()} or
* {@link #allMimeTypes(List, boolean)}.
* {@link #allMimeTypes(List, boolean)}
*/
@Deprecated
public static StringDecoder allMimeTypes(boolean ignored) {
@ -275,7 +274,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -275,7 +274,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
* Create a {@code StringDecoder} that supports all MIME types.
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting
* input strings.
* input strings
*/
public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
return new StringDecoder(delimiters, stripDelimiter,

27
spring-core/src/test/java/org/springframework/core/codec/StringDecoderTests.java

@ -34,12 +34,12 @@ import org.springframework.lang.Nullable; @@ -34,12 +34,12 @@ import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import static java.nio.charset.StandardCharsets.UTF_16BE;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.*;
import static org.junit.Assert.*;
/**
* Unit tests for {@link StringDecoder}.
*
* @author Sebastien Deleuze
* @author Brian Clozel
* @author Mark Paluch
@ -48,29 +48,21 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> { @@ -48,29 +48,21 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> {
private static final ResolvableType TYPE = ResolvableType.forClass(String.class);
public StringDecoderTests() {
super(StringDecoder.allMimeTypes());
}
@Override
@Test
public void canDecode() {
assertTrue(this.decoder.canDecode(
TYPE, MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(
TYPE, MimeTypeUtils.TEXT_HTML));
assertTrue(this.decoder.canDecode(
TYPE, MimeTypeUtils.APPLICATION_JSON));
assertTrue(this.decoder.canDecode(
TYPE, MimeTypeUtils.parseMimeType("text/plain;charset=utf-8")));
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.TEXT_HTML));
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.APPLICATION_JSON));
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.parseMimeType("text/plain;charset=utf-8")));
assertFalse(this.decoder.canDecode(
ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
assertFalse(this.decoder.canDecode(
ResolvableType.forClass(Object.class), MimeTypeUtils.APPLICATION_JSON));
}
@ -157,7 +149,6 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> { @@ -157,7 +149,6 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> {
@Test
public void decodeNewLineIncludeDelimiters() {
this.decoder = StringDecoder.allMimeTypes(StringDecoder.DEFAULT_DELIMITERS, false);
Flux<DataBuffer> input = Flux.just(
@ -219,7 +210,7 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> { @@ -219,7 +210,7 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> {
}
@Test
public void decodeToMonoWithEmptyFlux() throws InterruptedException {
public void decodeToMonoWithEmptyFlux() {
Flux<DataBuffer> input = Flux.empty();
testDecodeToMono(input, String.class, step -> step

11
spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java

@ -103,14 +103,9 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> { @@ -103,14 +103,9 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
@Override
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
if (super.canDecode(elementType, mimeType)) {
Class<?> outputClass = elementType.toClass();
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
outputClass.isAnnotationPresent(XmlType.class));
}
else {
return false;
}
Class<?> outputClass = elementType.toClass();
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
outputClass.isAnnotationPresent(XmlType.class)) && super.canDecode(elementType, mimeType);
}
@Override

Loading…
Cancel
Save