Polishing

This commit is contained in:
Juergen Hoeller
2018-08-13 13:42:19 +02:00
parent e306d3e83a
commit 0e3f23eeb7
8 changed files with 47 additions and 42 deletions

View File

@@ -47,17 +47,19 @@ import org.springframework.util.MimeTypeUtils;
import org.springframework.util.xml.StaxUtils;
/**
* Decodes a {@link DataBuffer} stream into a stream of {@link XMLEvent}s.
* That is, given the following XML:
* Decodes a {@link DataBuffer} stream into a stream of {@link XMLEvent XMLEvents}.
*
* <pre>{@code
* <root>
* <child>foo</child>
* <child>bar</child>
* </root>}
* <p>Given the following XML:
*
* <pre class="code">
* &lt;root>
* &lt;child&gt;foo&lt;/child&gt;
* &lt;child&gt;bar&lt;/child&gt;
* &lt;/root&gt;
* </pre>
*
* this method with result in a flux with the following events:
* this decoder will produce a {@link Flux} with the following events:
*
* <ol>
* <li>{@link javax.xml.stream.events.StartDocument}</li>
* <li>{@link javax.xml.stream.events.StartElement} {@code root}</li>
@@ -70,8 +72,8 @@ import org.springframework.util.xml.StaxUtils;
* <li>{@link javax.xml.stream.events.EndElement} {@code root}</li>
* </ol>
*
* Note that this decoder is not registered by default but used internally
* by other decoders who are there by default.
* <p>Note that this decoder is not registered by default but is used internally
* by other decoders which are registered by default.
*
* @author Arjen Poutsma
* @since 5.0
@@ -97,7 +99,7 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Flux<DataBuffer> flux = Flux.from(inputStream);
if (useAalto) {
if (this.useAalto) {
AaltoDataBufferToXmlEvent aaltoMapper = new AaltoDataBufferToXmlEvent();
return flux.flatMap(aaltoMapper)
.doFinally(signalType -> aaltoMapper.endOfInput());
@@ -135,15 +137,15 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
@Override
public Publisher<? extends XMLEvent> apply(DataBuffer dataBuffer) {
try {
streamReader.getInputFeeder().feedInput(dataBuffer.asByteBuffer());
this.streamReader.getInputFeeder().feedInput(dataBuffer.asByteBuffer());
List<XMLEvent> events = new ArrayList<>();
while (true) {
if (streamReader.next() == AsyncXMLStreamReader.EVENT_INCOMPLETE) {
if (this.streamReader.next() == AsyncXMLStreamReader.EVENT_INCOMPLETE) {
// no more events with what currently has been fed to the reader
break;
}
else {
XMLEvent event = eventAllocator.allocate(streamReader);
XMLEvent event = this.eventAllocator.allocate(this.streamReader);
events.add(event);
if (event.isEndDocument()) {
break;