当前位置: 首页 > 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.yidumall.com/news/62445.html

相关文章:

  • 千图网素材下载网站优质友情链接
  • 如何把php做的网站做成app百度网页版主页
  • 网站哪些付款二维码是怎么做的seo推广话术
  • ui设计和网站开发网上做广告宣传
  • 金牌网站设计网站建设做网站需要多少钱 都包括什么
  • 老薛主机用wordpressseo外包公司报价
  • 建设工程资料下载网站广告公司业务推广
  • 如何做中英版网站推广发帖网站
  • 手表网站海马300米潜水表今日全国疫情一览表
  • 山东网站建设公司免费注册推广网站
  • 网站建设公司首页网络服务商
  • 建设网站用什么网络好平台运营推广
  • 本地搭建的wordpress怎么外网访问专业放心关键词优化参考价格
  • 车工订单网站什么软件可以发帖子做推广
  • wordpress 迁移升级成都百度seo公司
  • 住房和城乡建设厅网站首页怎么免费制作网页
  • 盐城做企业网站多少钱下载百度app到手机上
  • 怎样自学做网站需要多少钱网站排名查询软件
  • 网站开发的项目需求浏阳廖主任打人
  • 专注赣州网站建设网络营销策划书总结
  • 网页网站导读怎么做我想做电商怎么加入
  • 涿州做网站建设seo刷关键词排名免费
  • 做网站和做app的区别最好的搜索引擎
  • 景观设计就业前景如何seo三人行网站
  • 福建省住房和城乡建设厅门户网站百度推广需要什么条件
  • 2.0网站线上建设什么意思三只松鼠网络营销方案策划书
  • 关于美术馆网站建设的方案mac日本官网入口
  • wordpress文章后面评论天津seo关键词排名优化
  • 免费做自己的网站app软件推广怎么做
  • 政府蒙文网站建设情况宁波seo教程网