CharStreamsTest.java 文件源码

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

项目:guava-libraries 作者:
/**
 * Returns a reader wrapping the given reader that only reads half of the maximum number of
 * characters that it could read in read(char[], int, int).
 */
private static Reader newNonBufferFillingReader(Reader reader) {
  return new FilterReader(reader) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      // if a buffer isn't being cleared correctly, this method will eventually start being called
      // with a len of 0 forever
      if (len <= 0) {
        fail("read called with a len of " + len);
      }
      // read fewer than the max number of chars to read
      // shouldn't be a problem unless the buffer is shrinking each call
      return in.read(cbuf, off, Math.max(len - 1024, 0));
    }
  };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号