core: add a `close` to InputBufferStream

Before:
`InputBufferStream.close()` does not close their buffer so the buffer will leak.

After:
Resolves #4198.
Override the `close` for closing their buffer.
This commit is contained in:
Shohei Kamimori 2018-04-04 00:18:01 +09:00 committed by Eric Anderson
parent bace06fe9f
commit 8f01084bb3
2 changed files with 14 additions and 0 deletions

View File

@ -327,6 +327,11 @@ public final class ReadableBuffers {
buffer.readBytes(dest, destOffset, length);
return length;
}
@Override
public void close() throws IOException {
buffer.close();
}
}
private ReadableBuffers() {}

View File

@ -21,6 +21,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.InputStream;
@ -119,4 +120,12 @@ public class ReadableBuffersTest {
assertEquals(2, inputStream.read(dest, /*destOffset*/ 1, /*length*/ 2));
assertArrayEquals(new byte[]{0x00, 'h', 'e'}, dest);
}
@Test
public void bufferInputStream_close_closesBuffer() throws Exception {
ReadableBuffer buffer = mock(ReadableBuffer.class);
InputStream inputStream = ReadableBuffers.openStream(buffer, true);
inputStream.close();
verify(buffer, times(1)).close();
}
}