/** * */ public static class MyMultipleFilesTextOutputFormat extends MultipleOutputFormat<Text, IntWritable> { private TextOutputFormat<Text, IntWritable> output = null; // 明确定义使用哪个 recordwriter类 @Override protected org.apache.hadoop.mapred.RecordWriter<Text, IntWritable> getBaseRecordWriter( FileSystem fs, JobConf job, String name, Progressable progress) throws IOException { final TextOutputFormat<Text, IntWritable> textOutputFormat = new TextOutputFormat<Text, IntWritable>(); if (output == null) { output = new TextOutputFormat<Text, IntWritable>(); } return textOutputFormat.getRecordWriter(fs, job, name, progress); } // 重写方法, 将生成输出文件文件名的方法进行重写 @Override protected String generateFileNameForKeyValue(Text key,IntWritable value, String name) { //输出的文件名就是k3的值 final String keyString = key.toString(); if(keyString.contains("download")) { return "download"; } else if(keyString.contains("upload")) { return "upload"; } else if(keyString.contains("debug")) { return "debug"; } else { return "others"; } } }