首页 > 其他 > 详细

Files

时间:2016-08-17 01:18:47      阅读:179      评论:0      收藏:0      [点我收藏+]

guava源码:Files

看一下它的调用过程

 public static <T> T readLines(File file, Charset charset,
    LineProcessor<T> callback) throws IOException {
  return asCharSource(file, charset).readLines(callback);
}

  asCharSource->asByteSource->FileByteSource

FileByteSource里 是用的FIleInputStream

 @Override
public FileInputStream openStream() throws IOException {
  return new FileInputStream(file);
}

在asByteSource里 对FIleByteSource转换 成BufferedReader

 public static BufferedReader newReader(File file, Charset charset)
    throws FileNotFoundException {
  checkNotNull(file);
  checkNotNull(charset);
  return new BufferedReader(
      new InputStreamReader(new FileInputStream(file), charset));
}

在ReadLines中

 public static <T> T readLines(
    Readable readable, LineProcessor<T> processor) throws IOException {
  checkNotNull(readable);
  checkNotNull(processor);

  LineReader lineReader = new LineReader(readable);
  String line;
  while ((line = lineReader.readLine()) != null) {
    if (!processor.processLine(line)) {
      break;
    }
  }
  return processor.getResult();
}

Files

原文:http://www.cnblogs.com/lijia0511/p/5778307.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!