MultiInputStreamTest.java 文件源码

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

项目:guava-libraries 作者:
public void testOnlyOneOpen() throws Exception {
  final ByteSource source = newByteSource(0, 50);
  final int[] counter = new int[1];
  ByteSource checker = new ByteSource() {
    @Override
    public InputStream openStream() throws IOException {
      if (counter[0]++ != 0) {
        throw new IllegalStateException("More than one source open");
      }
      return new FilterInputStream(source.openStream()) {
        @Override public void close() throws IOException {
          super.close();
          counter[0]--;
        }
      };
    }
  };
  byte[] result = ByteSource.concat(checker, checker, checker).read();
  assertEquals(150, result.length);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号