Delay DataBuffer release until stream is closed

This commit changes the release of data buffers from a finally block
into a `doFinally()` lambda on the returned `Flux<XMLEvent>` stream.

Issue: SPR-15707
This commit is contained in:
Arjen Poutsma 2017-06-29 16:19:03 +02:00
parent b1f06fddd2
commit 9d7b8503d0
1 changed files with 4 additions and 4 deletions

View File

@ -106,14 +106,14 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
try {
InputStream is = dataBuffer.asInputStream();
Iterator eventReader = inputFactory.createXMLEventReader(is);
return Flux.fromIterable((Iterable<XMLEvent>) () -> eventReader);
return Flux.fromIterable((Iterable<XMLEvent>) () -> eventReader)
.doFinally(t -> {
DataBufferUtils.release(dataBuffer);
});
}
catch (XMLStreamException ex) {
return Mono.error(ex);
}
finally {
DataBufferUtils.release(dataBuffer);
}
});
}
}