java api读取RCFile

private static List<String> showRCFile (Path src,Configuration conf) {
		List<String> list = new ArrayList<String>();
		try {
			FileSystem fs = FileSystem.get(src.toUri(), conf);
			long fileLen = fs.getFileStatus(src).getLen();
			FileSplit split = new FileSplit(src,0, fileLen, new JobConf(conf));
			RCFileRecordReader recordReader = new RCFileRecordReader(conf, split);
			LongWritable key = new LongWritable();
		    BytesRefArrayWritable value = new BytesRefArrayWritable();
		    Text txt = new Text();
		    String resultStr = null;
		    int y = 0;
		    while (recordReader.next(key, value)) {
		      //if (y == 10) break;
		      resultStr = "";
		      txt.clear();
		      for (int i = 0; i < value.size(); i++) {
		        BytesRefWritable v = value.get(i);
		        txt.set(v.getData(), v.getStart(), v.getLength());
		        resultStr = resultStr + txt.toString();
		        if (i < value.size() - 1) {
		          // do not put the TAB for the last column
		        	resultStr = resultStr + TAB;
		        }
		      }
		      resultStr = resultStr + NEWLINE;
		      list.add(resultStr);
		      y++;
		    }
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
		
	}
 

你可能感兴趣的:(java)