Polishing

This commit is contained in:
Juergen Hoeller 2018-12-03 23:53:00 +01:00
parent d5dab12909
commit 6d7827e36b
3 changed files with 20 additions and 35 deletions

View File

@ -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> {
}
/**
* 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> {
* 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> {
* 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> {
* 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> {
* 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,

View File

@ -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> {
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> {
@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> {
}
@Test
public void decodeToMonoWithEmptyFlux() throws InterruptedException {
public void decodeToMonoWithEmptyFlux() {
Flux<DataBuffer> input = Flux.empty();
testDecodeToMono(input, String.class, step -> step

View File

@ -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