Polishing
This commit is contained in:
parent
d5dab12909
commit
6d7827e36b
|
|
@ -110,8 +110,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits the given data buffer on delimiter boundaries. The returned Flux contains a
|
* Split the given data buffer on delimiter boundaries.
|
||||||
* {@link #END_FRAME} buffer after each delimiter.
|
* The returned Flux contains an {@link #END_FRAME} buffer after each delimiter.
|
||||||
*/
|
*/
|
||||||
private List<DataBuffer> splitOnDelimiter(DataBuffer dataBuffer, List<byte[]> delimiterBytes) {
|
private List<DataBuffer> splitOnDelimiter(DataBuffer dataBuffer, List<byte[]> delimiterBytes) {
|
||||||
List<DataBuffer> frames = new ArrayList<>();
|
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) {
|
private static boolean isEndFrame(DataBuffer dataBuffer) {
|
||||||
return dataBuffer == END_FRAME;
|
return dataBuffer == END_FRAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Joins the given list of buffers into a single buffer, also removing
|
* Join the given list of buffers into a single buffer.
|
||||||
* the (inserted) {@link #END_FRAME}.
|
|
||||||
*/
|
*/
|
||||||
private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) {
|
private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) {
|
||||||
if (!dataBuffers.isEmpty()) {
|
if (!dataBuffers.isEmpty()) {
|
||||||
|
|
@ -229,7 +228,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||||
* Create a {@code StringDecoder} for {@code "text/plain"}.
|
* Create a {@code StringDecoder} for {@code "text/plain"}.
|
||||||
* @param ignored ignored
|
* @param ignored ignored
|
||||||
* @deprecated as of Spring 5.0.4, in favor of {@link #textPlainOnly()} or
|
* @deprecated as of Spring 5.0.4, in favor of {@link #textPlainOnly()} or
|
||||||
* {@link #textPlainOnly(List, boolean)}.
|
* {@link #textPlainOnly(List, boolean)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static StringDecoder textPlainOnly(boolean ignored) {
|
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"}.
|
* Create a {@code StringDecoder} for {@code "text/plain"}.
|
||||||
* @param delimiters delimiter strings to use to split the input stream
|
* @param delimiters delimiter strings to use to split the input stream
|
||||||
* @param stripDelimiter whether to remove delimiters from the resulting
|
* @param stripDelimiter whether to remove delimiters from the resulting
|
||||||
* input strings.
|
* input strings
|
||||||
*/
|
*/
|
||||||
public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
|
public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
|
||||||
return new StringDecoder(delimiters, stripDelimiter, new MimeType("text", "plain", DEFAULT_CHARSET));
|
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.
|
* Create a {@code StringDecoder} that supports all MIME types.
|
||||||
* @param ignored ignored
|
* @param ignored ignored
|
||||||
* @deprecated as of Spring 5.0.4, in favor of {@link #allMimeTypes()} or
|
* @deprecated as of Spring 5.0.4, in favor of {@link #allMimeTypes()} or
|
||||||
* {@link #allMimeTypes(List, boolean)}.
|
* {@link #allMimeTypes(List, boolean)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static StringDecoder allMimeTypes(boolean ignored) {
|
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.
|
* Create a {@code StringDecoder} that supports all MIME types.
|
||||||
* @param delimiters delimiter strings to use to split the input stream
|
* @param delimiters delimiter strings to use to split the input stream
|
||||||
* @param stripDelimiter whether to remove delimiters from the resulting
|
* @param stripDelimiter whether to remove delimiters from the resulting
|
||||||
* input strings.
|
* input strings
|
||||||
*/
|
*/
|
||||||
public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
|
public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
|
||||||
return new StringDecoder(delimiters, stripDelimiter,
|
return new StringDecoder(delimiters, stripDelimiter,
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_16BE;
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link StringDecoder}.
|
* Unit tests for {@link StringDecoder}.
|
||||||
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
|
@ -48,29 +48,21 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> {
|
||||||
|
|
||||||
private static final ResolvableType TYPE = ResolvableType.forClass(String.class);
|
private static final ResolvableType TYPE = ResolvableType.forClass(String.class);
|
||||||
|
|
||||||
|
|
||||||
public StringDecoderTests() {
|
public StringDecoderTests() {
|
||||||
super(StringDecoder.allMimeTypes());
|
super(StringDecoder.allMimeTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void canDecode() {
|
public void canDecode() {
|
||||||
assertTrue(this.decoder.canDecode(
|
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.TEXT_PLAIN));
|
||||||
TYPE, MimeTypeUtils.TEXT_PLAIN));
|
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.TEXT_HTML));
|
||||||
|
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.APPLICATION_JSON));
|
||||||
assertTrue(this.decoder.canDecode(
|
assertTrue(this.decoder.canDecode(TYPE, MimeTypeUtils.parseMimeType("text/plain;charset=utf-8")));
|
||||||
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(
|
assertFalse(this.decoder.canDecode(
|
||||||
ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
|
ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
|
||||||
|
|
||||||
assertFalse(this.decoder.canDecode(
|
assertFalse(this.decoder.canDecode(
|
||||||
ResolvableType.forClass(Object.class), MimeTypeUtils.APPLICATION_JSON));
|
ResolvableType.forClass(Object.class), MimeTypeUtils.APPLICATION_JSON));
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +149,6 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decodeNewLineIncludeDelimiters() {
|
public void decodeNewLineIncludeDelimiters() {
|
||||||
|
|
||||||
this.decoder = StringDecoder.allMimeTypes(StringDecoder.DEFAULT_DELIMITERS, false);
|
this.decoder = StringDecoder.allMimeTypes(StringDecoder.DEFAULT_DELIMITERS, false);
|
||||||
|
|
||||||
Flux<DataBuffer> input = Flux.just(
|
Flux<DataBuffer> input = Flux.just(
|
||||||
|
|
@ -219,7 +210,7 @@ public class StringDecoderTests extends AbstractDecoderTestCase<StringDecoder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decodeToMonoWithEmptyFlux() throws InterruptedException {
|
public void decodeToMonoWithEmptyFlux() {
|
||||||
Flux<DataBuffer> input = Flux.empty();
|
Flux<DataBuffer> input = Flux.empty();
|
||||||
|
|
||||||
testDecodeToMono(input, String.class, step -> step
|
testDecodeToMono(input, String.class, step -> step
|
||||||
|
|
|
||||||
|
|
@ -103,14 +103,9 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
|
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
|
||||||
if (super.canDecode(elementType, mimeType)) {
|
Class<?> outputClass = elementType.toClass();
|
||||||
Class<?> outputClass = elementType.toClass();
|
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
|
||||||
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
|
outputClass.isAnnotationPresent(XmlType.class)) && super.canDecode(elementType, mimeType);
|
||||||
outputClass.isAnnotationPresent(XmlType.class));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue