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:
@@ -182,6 +182,27 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
|
||||
release(buffer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReleaseOnClose() throws IOException {
|
||||
DataBuffer buffer = createDataBuffer(3);
|
||||
byte[] bytes = {'a', 'b', 'c'};
|
||||
buffer.write(bytes);
|
||||
|
||||
InputStream inputStream = buffer.asInputStream(true);
|
||||
|
||||
try {
|
||||
byte[] result = new byte[3];
|
||||
int len = inputStream.read(result);
|
||||
assertEquals(3, len);
|
||||
assertArrayEquals(bytes, result);
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
|
||||
// AbstractDataBufferAllocatingTestCase.LeakDetector will verify the buffer's release
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputStream() throws IOException {
|
||||
DataBuffer buffer = createDataBuffer(4);
|
||||
|
||||
Reference in New Issue
Block a user