/**
*
* @param job 配置信息
* @param split split
* @param recordDelimiter 分列的字符
* @throws IOException
*/
public LineRecordReader(Configuration job, FileSplit split,
byte[] recordDelimiter) throws IOException {
//如果没有配置每一行的最大长度,那么每行默认的最大长度为Integer类型的最大值
this.maxLineLength = job.getInt(org.apache.hadoop.mapreduce.lib.input.
LineRecordReader.MAX_LINE_LENGTH, Integer.MAX_VALUE);
start = split.getStart();
end = start + split.getLength();
final Path file = split.getPath();
//默认io.compression.codecs gzip
compressionCodecs = new CompressionCodecFactory(job);
codec = compressionCodecs.getCodec(file); // open the file and seek to the start of the split
final FileSystem fs = file.getFileSystem(job);
fileIn = fs.open(file);
if (isCompressedInput()) {
decompressor = CodecPool.getDecompressor(codec);
if (codec instanceof SplittableCompressionCodec) {
final SplitCompressionInputStream cIn =
((SplittableCompressionCodec)codec).createInputStream(
fileIn, decompressor, start, end,
SplittableCompressionCodec.READ_MODE.BYBLOCK);
in = new CompressedSplitLineReader(cIn, job, recordDelimiter);
start = cIn.getAdjustedStart();
end = cIn.getAdjustedEnd();
filePosition = cIn; // take pos from compressed stream
} else {
in = new SplitLineReader(codec.createInputStream(fileIn,
decompressor), job, recordDelimiter);
filePosition = fileIn;
}
} else {
//从打开的文件找到指定位置
fileIn.seek(start);
in = new SplitLineReader(fileIn, job, recordDelimiter);
filePosition = fileIn;
}
// If this is not the first split, we always throw away first record
// because we always (except the last split) read one extra line in
// next() method.
//如果不是第一个dplit,那么将start设置成当前位置+第一行的长度。
//跨过第一行,因为第一行数据已经在上一个split中读取了
if (start != 0) {
start += in.readLine(new Text(), 0, maxBytesToConsume(start));
}
this.pos = start;
}

最新文章

  1. DevExpress 13.1.8全面支持VS2013
  2. iOS——关于打印控件
  3. 基于Web的企业网和互联网的信息和应用( 1194.22 )
  4. bzoj3798: 特殊的质数
  5. HDOJ-ACM1003(JAVA)
  6. 九度OJ 1516 调整数组顺序使奇数位于偶数前面 -- 归并排序
  7. ActiveMQ入门实例(转)
  8. 【HDU3341】 Lost's revenge (AC自动机+状压DP)
  9. Sql自动生成字母加数字的随机数
  10. android 之 百度地图
  11. SQLServer行转列
  12. .NET Framework不同组件区别及安装注意事项
  13. ie 如何判断正在执行的脚本
  14. WPF中,多key值绑定问题,一个key绑定一个界面上的对象
  15. 《精通Spring+4.x++企业应用开发实战》读后感
  16. FORTH 发展(部分)
  17. HDU/HDOJ 1867 A + B for you again
  18. bootstrap 中关于 HTML5 aria-* and role的用法
  19. 三 drf 认证,权限,限流,过滤,排序,分页,异常处理,接口文档,集xadmin的使用
  20. 洛谷 P4127 [AHOI2009]同类分布 解题报告

热门文章

  1. elemetUi 组件--el-upload
  2. java JDK动态代理的机制
  3. Servlet的doGet与doPost方法的区别与使用
  4. centos 下构建lamp环境
  5. 会议中心[APIO2009]
  6. bzoj 1005 组合数学 Purfer Sequence
  7. 内置函数补充,__str__方法、__del__方法 和 __call__方法和元祖
  8. 用maven创建第一个SpringMVC
  9. 【转载】Window 窗口层次关系
  10. Centos 7 设置 DNS