Skip to content

Commit c13f841

Browse files
committed
Minor revision of reactive support layout (ahead of 5.0 M1)
DataSourceUtils moved to main core.io.buffer package. Consistently named Jackson2JsonDecoder/Encoder and Jaxb2XmlDecoder/Encoder. Plenty of related polishing.
1 parent 3d6a5bc commit c13f841

File tree

51 files changed

+335
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+335
-378
lines changed

spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.core.codec;
1818

1919
import java.util.Arrays;
20-
import java.util.Collections;
2120
import java.util.List;
2221

2322
import org.reactivestreams.Publisher;
@@ -36,7 +35,7 @@
3635
*/
3736
public abstract class AbstractDecoder<T> implements Decoder<T> {
3837

39-
private List<MimeType> decodableMimeTypes = Collections.emptyList();
38+
private final List<MimeType> decodableMimeTypes;
4039

4140

4241
protected AbstractDecoder(MimeType... supportedMimeTypes) {
@@ -54,7 +53,7 @@ public boolean canDecode(ResolvableType elementType, MimeType mimeType, Object..
5453
if (mimeType == null) {
5554
return true;
5655
}
57-
return this.decodableMimeTypes.stream().anyMatch(m -> m.isCompatibleWith(mimeType));
56+
return this.decodableMimeTypes.stream().anyMatch(candidate -> candidate.isCompatibleWith(mimeType));
5857
}
5958

6059
@Override

spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.core.codec;
1818

1919
import java.util.Arrays;
20-
import java.util.Collections;
2120
import java.util.List;
2221

2322
import org.springframework.core.ResolvableType;
@@ -32,7 +31,7 @@
3231
*/
3332
public abstract class AbstractEncoder<T> implements Encoder<T> {
3433

35-
private List<MimeType> encodableMimeTypes = Collections.emptyList();
34+
private final List<MimeType> encodableMimeTypes;
3635

3736

3837
protected AbstractEncoder(MimeType... supportedMimeTypes) {
@@ -50,7 +49,7 @@ public boolean canEncode(ResolvableType elementType, MimeType mimeType, Object..
5049
if (mimeType == null) {
5150
return true;
5251
}
53-
return this.encodableMimeTypes.stream().anyMatch(m -> m.isCompatibleWith(mimeType));
52+
return this.encodableMimeTypes.stream().anyMatch(candidate -> candidate.isCompatibleWith(mimeType));
5453
}
5554

5655
}

spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ public AbstractSingleValueEncoder(MimeType... supportedMimeTypes) {
4040

4141

4242
@Override
43-
public final Flux<DataBuffer> encode(Publisher<? extends T> inputStream,
44-
DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType,
45-
Object... hints) {
43+
public final Flux<DataBuffer> encode(Publisher<? extends T> inputStream, DataBufferFactory bufferFactory,
44+
ResolvableType elementType, MimeType mimeType, Object... hints) {
4645

4746
return Flux.from(inputStream).
4847
take(1).

spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.springframework.core.ResolvableType;
2525
import org.springframework.core.io.buffer.DataBuffer;
26-
import org.springframework.core.io.buffer.support.DataBufferUtils;
26+
import org.springframework.core.io.buffer.DataBufferUtils;
2727
import org.springframework.util.MimeType;
2828
import org.springframework.util.MimeTypeUtils;
2929

@@ -36,7 +36,6 @@
3636
*/
3737
public class ByteBufferDecoder extends AbstractDecoder<ByteBuffer> {
3838

39-
4039
public ByteBufferDecoder() {
4140
super(MimeTypeUtils.ALL);
4241
}
@@ -61,4 +60,4 @@ public Flux<ByteBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType
6160
});
6261
}
6362

64-
}
63+
}

spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
*/
3636
public class ByteBufferEncoder extends AbstractEncoder<ByteBuffer> {
3737

38-
3938
public ByteBufferEncoder() {
4039
super(MimeTypeUtils.ALL);
4140
}
@@ -55,4 +54,4 @@ public Flux<DataBuffer> encode(Publisher<? extends ByteBuffer> inputStream,
5554
return Flux.from(inputStream).map(bufferFactory::wrap);
5655
}
5756

58-
}
57+
}

spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.springframework.util.MimeType;
3131

3232
/**
33-
* Encode from a CharSequence stream to a bytes stream.
33+
* Encode from a {@code CharSequence} stream to a bytes stream.
3434
*
3535
* @author Sebastien Deleuze
3636
* @author Arjen Poutsma

spring-core/src/main/java/org/springframework/core/codec/CodecException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -27,12 +27,12 @@
2727
@SuppressWarnings("serial")
2828
public class CodecException extends NestedRuntimeException {
2929

30-
public CodecException(String msg, Throwable cause) {
31-
super(msg, cause);
32-
}
33-
3430
public CodecException(String msg) {
3531
super(msg);
3632
}
3733

34+
public CodecException(String msg, Throwable cause) {
35+
super(msg, cause);
36+
}
37+
3838
}

spring-core/src/main/java/org/springframework/core/codec/Decoder.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
*
3333
* @author Sebastien Deleuze
3434
* @author Rossen Stoyanchev
35-
* @param <T> the type of elements in the output stream
3635
* @since 5.0
36+
* @param <T> the type of elements in the output stream
3737
*/
3838
public interface Decoder<T> {
3939

4040
/**
4141
* Whether the decoder supports the given target element type and the MIME
4242
* type of the source stream.
43-
*
4443
* @param elementType the target element type for the output stream
4544
* @param mimeType the mime type associated with the stream to decode
4645
* @param hints additional information about how to do decode, optional
@@ -50,7 +49,6 @@ public interface Decoder<T> {
5049

5150
/**
5251
* Decode a {@link DataBuffer} input stream into a Flux of {@code T}.
53-
*
5452
* @param inputStream the {@code DataBuffer} input stream to decode
5553
* @param elementType the expected type of elements in the output stream;
5654
* this type must have been previously passed to the {@link #canDecode}
@@ -64,7 +62,6 @@ Flux<T> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
6462

6563
/**
6664
* Decode a {@link DataBuffer} input stream into a Mono of {@code T}.
67-
*
6865
* @param inputStream the {@code DataBuffer} input stream to decode
6966
* @param elementType the expected type of elements in the output stream;
7067
* this type must have been previously passed to the {@link #canDecode}

spring-core/src/main/java/org/springframework/core/codec/Encoder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
*
3333
* @author Sebastien Deleuze
3434
* @author Rossen Stoyanchev
35-
* @param <T> the type of elements in the input stream
3635
* @since 5.0
36+
* @param <T> the type of elements in the input stream
3737
*/
3838
public interface Encoder<T> {
3939

4040
/**
4141
* Whether the encoder supports the given source element type and the MIME
4242
* type for the output stream.
43-
*
4443
* @param elementType the type of elements in the source stream
4544
* @param mimeType the MIME type for the output stream
4645
* @param hints additional information about how to do encode, optional
@@ -51,7 +50,6 @@ public interface Encoder<T> {
5150
/**
5251
* Encode a stream of Objects of type {@code T} into a {@link DataBuffer}
5352
* output stream.
54-
*
5553
* @param inputStream the input stream of Objects to encode
5654
* @param bufferFactory for creating output stream {@code DataBuffer}'s
5755
* @param elementType the expected type of elements in the input stream;

spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.core.io.InputStreamResource;
2828
import org.springframework.core.io.Resource;
2929
import org.springframework.core.io.buffer.DataBuffer;
30-
import org.springframework.core.io.buffer.support.DataBufferUtils;
30+
import org.springframework.core.io.buffer.DataBufferUtils;
3131
import org.springframework.util.MimeType;
3232
import org.springframework.util.MimeTypeUtils;
3333

@@ -39,7 +39,6 @@
3939
*/
4040
public class ResourceDecoder extends AbstractDecoder<Resource> {
4141

42-
4342
public ResourceDecoder() {
4443
super(MimeTypeUtils.ALL);
4544
}
@@ -79,4 +78,5 @@ else if (clazz.isAssignableFrom(ByteArrayResource.class)) {
7978
return Flux.error(new IllegalStateException("Unsupported resource class: " + clazz));
8079
}
8180
}
81+
8282
}

0 commit comments

Comments
 (0)