FileBackedInputStreamTest.java 文件源码

java
阅读 38 收藏 0 点赞 0 评论 0

项目:dw-jdbc 作者:
@Test
public void testDownloadException() throws Exception {
    byte[] content = genSampleBytes(8000);
    // Simulate the socket being closed before all expected bytes were downloaded.
    InputStream contentIn = new FilterInputStream(new ByteArrayInputStream(content)) {
        @Override
        public int read(@Nonnull byte[] b, int off, int len) throws IOException {
            int count = super.read(b, off, len);
            if (count == -1) {
                throw new EOFException("Unexpected end of input");
            }
            return count;
        }
    };
    try (InputStream in = new FileBackedInputStream(contentIn, 0, newCachedExecutor())) {
        //noinspection ResultOfMethodCallIgnored
        assertThatThrownBy(() -> in.skip(10000))
                .isExactlyInstanceOf(IOException.class)
                .hasMessage("Unexpected end of input")
                .hasCauseExactlyInstanceOf(EOFException.class);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号