Allow "release on close" for DataBuffer.asInputStream

This commit introduces DataBuffer.asInputStream(boolean), that can
release the underlying buffer when the stream is closed.

Furthermore, this commit adds additional javadoc.

Issue: SPR-16444
This commit is contained in:
Arjen Poutsma
2018-02-08 10:11:53 +01:00
parent 4318710b9b
commit fb61af1882
5 changed files with 60 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.PooledDataBuffer;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
@@ -210,8 +211,14 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
@Override
public boolean release() {
this.pooledByteBuffer.close();
return this.pooledByteBuffer.isOpen();
boolean result;
try {
result = DataBufferUtils.release(this.dataBuffer);
}
finally {
this.pooledByteBuffer.close();
}
return result && this.pooledByteBuffer.isOpen();
}
@Override
@@ -338,6 +345,11 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
return this.dataBuffer.asInputStream();
}
@Override
public InputStream asInputStream(boolean releaseOnClose) {
return this.dataBuffer.asInputStream(releaseOnClose);
}
@Override
public OutputStream asOutputStream() {
return this.dataBuffer.asOutputStream();