当前位置: 首页 > news >正文

周口网站设计优化神马网站关键词排名价格

周口网站设计,优化神马网站关键词排名价格,化妆品网站模板免费下载,普陀做网站公司要求 多个小文件合并,要求将文件合并到SequenceFile中 SequenceFile对外是一个整体,对内还是一个个的文件 期望结果是: key:每一个小文件的带路径的文件名value:每一个小文件的文件内容 第一步:自定义…

要求

多个小文件合并,要求将文件合并到SequenceFile中

SequenceFile对外是一个整体,对内还是一个个的文件

期望结果是:

  • key:每一个小文件的带路径的文件名
  • value:每一个小文件的文件内容
    在这里插入图片描述

第一步:自定义RecordReader类

public class FileCombineRecordReader extends RecordReader<Text, BytesWritable> {//每一个切片(小文件)调用一次这个类private FileSplit split;private Configuration cfg;private boolean isProcess = false;private Text key = new Text();private BytesWritable value = new BytesWritable();@Overridepublic void initialize(InputSplit inputSplit, TaskAttemptContext Context) {this.split = (FileSplit) inputSplit;cfg = Context.getConfiguration();}@Override//核心业务逻辑public boolean nextKeyValue() throws IOException {//一次读取一个完整的文件并封装到KV中if (!isProcess) {byte[] buf = new byte[(int) split.getLength()]; //1.根据切片长度定义缓冲区Path path = split.getPath();//2.获得路径FileSystem fs = path.getFileSystem(cfg); //3.通过路径获得文件系统FSDataInputStream fis = fs.open(path); //4.通过文件系统获得输入流IOUtils.readFully(fis, buf, 0, buf.length);   //5.拷贝流key.set(split.getPath().toString());//设置key值为文件的路径+名称value.set(buf, 0, buf.length);//将buf中的内容输出到value中IOUtils.closeStream(fis);IOUtils.closeStream(fs);//6.关闭流isProcess = true;//读完之后结束return true;}return false;}@Overridepublic Text getCurrentKey() {//获取当前的keyreturn key;}@Overridepublic BytesWritable getCurrentValue() {//获取当前的valuereturn value;}@Overridepublic float getProgress() {//获取正在处理的进度return 0;}@Overridepublic void close() {}
}

第二步:自定义InputFromat

public class FileCombineInputFormat extends FileInputFormat<Text, BytesWritable> {@Overrideprotected boolean isSplitable(JobContext context, Path filename) {return false; //原文件不可切割}@Overridepublic RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) {FileCombineRecordReader recordReader = new FileCombineRecordReader();//自定义RecordReader对象并初始化recordReader.initialize(split,context);return recordReader;}
}

第三步:编写Mapper类

public class FileCombineMapper extends Mapper<Text, BytesWritable, Text, BytesWritable> {@Overrideprotected void map(Text key, BytesWritable value, Context context) throws IOException, InterruptedException {context.write(key, value);}
}

第四步:编写Reducer类

public class FileCombineReducer extends Reducer<Text, BytesWritable, Text, BytesWritable> {@Overrideprotected void reduce(Text key, Iterable<BytesWritable> values, Context context) throws IOException, InterruptedException {//循环写出for(BytesWritable value : values){context.write(key, value);}}
}

第五步:编写SequenceFileDriver类

public class FileCombineDriver {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {// 数据输入路径和输出路径args = new String[2];args[0] = "src/main/resources/aai/";args[1] = "src/main/resources/aao";Configuration cfg = new Configuration();//设置本地模式运行(即使项目类路径下core-site.xml文件,依然采用本地模式)cfg.set("mapreduce.framework.name", "local");cfg.set("fs.defaultFS", "file:///");Job job = Job.getInstance(cfg);job.setJarByClass(FileCombineDriver.class);job.setMapperClass(FileCombineMapper.class);job.setReducerClass(FileCombineReducer.class);//设置inputFormat为自定义的FileCombileInputFormatjob.setInputFormatClass(FileCombineInputFormat.class);job.setOutputFormatClass(SequenceFileOutputFormat.class);//设置输出的outputFormatjob.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(BytesWritable.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(BytesWritable.class);FileInputFormat.setInputPaths(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));boolean b = job.waitForCompletion(true);System.out.println(b);}
}
http://www.shuangfujiaoyu.com/news/31313.html

相关文章:

  • 网站需要公司备案么最好用的手机优化软件
  • 网页游戏网站哪个最好seo自学网视频教程
  • 上海十大金融投资公司排名seo推广多少钱
  • php网站开发环境的设置广东东莞最新情况
  • 大学生心里健康网站设计与建设百度指数手机版
  • 做网站包含微信公众号吗百度图片识别在线使用
  • 互联网行业网站设计网络营销与传统营销的整合
  • 做移动端电影网站谷歌sem
  • 网站空间 程序有限制吗推广app平台有哪些
  • 用dw做网站的流程怎么做百度网页推广
  • 如何用家用电脑做网站精准推广
  • 做暧昧在线网站如何建立一个自己的网站?
  • 专业免费网站建设一般多少钱百度风云排行榜官网
  • 如何做网站监控seo排名工具
  • 弹性云主机做网站免费b2b网站推广渠道
  • 怎样制作单页网站seo整站优化推广
  • qq网站官网看b站视频软件下载安装手机
  • 深圳网站建设yuntianxia常见的系统优化软件
  • 电影里的做视频在线观看网站百度热线客服24小时
  • 北京网站建设公司 蓝纤科技 网络服务2022最新新闻
  • 怎么做提升自己的网站整合网络营销外包
  • 全国做网站公司排名域名权重
  • 空间站天宫vr全景seo技术推广
  • 日本人真人做真爱的网站知名的建站公司
  • 做公司网站计入什么会计科目从事网络营销的公司
  • dreamweaver 8完美网页设计 商业网站篇百度seo综合查询
  • 手机制作app需要什么软件天津seo
  • 设计优秀的企业网站今日热搜榜排名最新
  • 网站的外部推广中国万网域名注册免费
  • 自己做的网站怎么加入微信支付seo外包公司一般费用是多少