This is the eighth day of my participation in the August More text Challenge. For details, see: August More Text Challenge
decoder
First spring defines a top-level interface, Decoder, that conventions some of the public methods for decoding.
CanDecode method
boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType);
Copy the code
Whether the decoder operation can be performed is equivalent to meeting the specified conditions before the decoder operation can be performed. Is a precondition, where the input parameters are ResolvableType and MimeType, respectively.
- ResolvableType
A wrapper around a Java type that can be used to access parent classes, interfaces, parameters, and so on
private HashMap<Integer, List<String>> myMap;
public void example(a) {
ResolvableType t = ResolvableType.forField(getClass().getDeclaredField("myMap"));
t.getSuperType(); // AbstractMap<Integer, List<String>>
t.asMap(); // Map<Integer, List<String>>
t.getGeneric(0).resolve(); // Integer
t.getGeneric(1).resolve(); // List
t.getGeneric(1); // List<String>
t.resolveGeneric(1.0); // String
}
Copy the code
- MimeType
Multipurpose Internet Mail Extensions (MIME) is an Internet standard that describes message content types. MIME messages can contain text, images, audio, video, and other application-specific data. The official MIME information is provided by the Internet Engineering Task Force (IETF) in the following document:
- RFC-822 Standard for ARPA Internet text messages
- RFC-2045 MIME Part 1: Format of Internet Message Bodies
- RFC-2046 MIME Part 2: Media Types
- RFC-2047 MIME Part 3: Header Extensions for Non-ASCII Text
- RFC-2048 MIME Part 4: Registration Procedures
- RFC-2049 MIME Part 5: Conformance Criteria and Examples
Different applications support different MIME types.
This is a standard protocol definition, subclassed by the common MediaType class, which contains HTTP definitions.
Decode method (based on Flux/Mono, responsive)
Flux<T> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints);
Copy the code
The reason why Flux is a responsive output stream type interface defined by Spring is that the underlying reference is a third-party Reactor, which integrates the CorePublisher interface and encapsulates a large number of methods for use by submodules. Currently, we can also develop some processing logic based on Flux.
By the way, a response flow has the following basic characteristics: first, it must be a non-blocking, asynchronously executing data flow that can handle back pressure. 1) Flux is a Publisher that emits an asynchronous sequence of 0-N elements that can be terminated by onComplete or onError signals. There are three methods called to downstream consumers in the response flow specification onNext, onComplete, and onError. 2) Mono is a 0-1 element Publisher that can be terminated by an onCmplete or onError signal. Similar to Flux, except that only 0-1 elements are emitted.
Ok, and finally paste the entire call diagram