当前位置: 首页 > 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/101392.html

相关文章:

  • 怎么给别人做网站优化怎样做网站平台
  • 珲春网站建设临沂网站建设优化
  • 物流公司官方网站建设方案口碑营销策略
  • 香水网站设计网页成人教育机构排行前十名
  • 怎么查询网站真假备案济南seo外贸网站建设
  • 福州网站开发定制沧州网站运营公司
  • 太原做网站武汉武汉最新
  • 有帮人做网站的人吗新闻发布平台
  • dede网站qq类资源源码注册网站怎么注册
  • 怎么在百度自己创网站小程序推广的十种方式
  • 关于解决网站 建设经费的请示汕头seo不错
  • 如何访问自己做的网站互联网项目
  • 大连全套网站建设接广告的网站
  • 怎么做移动端网站计算像素腾讯广点通广告投放平台
  • 可以做ps的网站2022最新时事新闻及点评
  • 竞价推广网站建设济南优化seo公司
  • 电子商务网站 费用四年级2023新闻摘抄
  • php跳转到其他网站网店推广运营策略
  • 莱芜杂谈莱芜在线论坛网站建设优化的技巧
  • 台州网站推广南宁百度seo建议
  • 品牌网站建设 细致磐石网络企业网络营销顾问
  • web前端技术栈有哪些信阳seo优化
  • 中国电商网站排行榜seo专业学校
  • 织梦网站后台logo删除常用的网络推广的方法有哪些
  • 中国城乡住房建设厅网站正规网站建设服务
  • 做基金哪个网站好app拉新项目一手渠道商
  • wordpress知更鸟模板seo推广网址
  • 网站备案时间就是正式上线时间吗友链交易
  • 住房和城乡建设部网站买卖合同应用宝下载
  • 招聘网站如何做推广杭州网站seo公司