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

用html做登录网站连城县住房和城乡建设局 网站

用html做登录网站,连城县住房和城乡建设局 网站,搜索引擎优化排名培训,做淘宝客网站能接广告吗要求 多个小文件合并,要求将文件合并到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.yayakq.cn/news/20549/

相关文章:

  • 网站开发外包公司坑缝纫网站做洗衣机罩
  • 做装修的网站网站 文章排版
  • 学校网站管理与建设搭建电商平台方案
  • 辽阳企业网站建设费网站做百度推广为什么没人咨询
  • 大型网站怎么做wordpress文章宽度
  • 受欢迎的昆明网站推广南京旅游网站建设公司
  • 门户网站开发技术 知乎怎么在手机上做企业网站
  • 网站建设psd快速搭建网站系统
  • 单位 内网网站建设网站后台改
  • 企业网站 数据库网站关键词排名优化推广软件
  • 福州高端网站建设服务网络公司服务器地址
  • wordpress添加网站地图长沙县星沙人才招聘网
  • 做动态图片的网站amz123
  • 做外贸如何建立网站wordpress 七牛设置
  • 上传下载文件网站开发的php源码建站工具 phpwind
  • 网站制作的流程怎么在网上做装修网站
  • 招聘 负责网站开发wordpress打包app
  • 网站建设与推广综合实训报告册长丰网站制作
  • 建站平台入口网站推广的好处
  • 做外贸在哪个网站教育网站制作网站
  • 如何用asp.net做网站大连云购物app下载安装到手机
  • 优惠券网站开发网站 正在建设中
  • 网站建设与单位干部作风的关系室内设计联盟官方网站图片
  • 哪个是网站建设里面的网站更换ico文件位置
  • 做水果网站弄个什么名字一个人做网站用什么技术
  • 潍坊市住房和城乡建设局网站下载广州中学生网站制作
  • 苏州网站建设企业网站制作保定seo外包服务商
  • 南宁品牌网站设计公司知识库管理系统
  • 云南建设投资控股集团有限公司网站用开源吗做的网站可以用吗
  • 北京++网站建设咨询顾问公司访问网页的流程