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

相关文章:

  • 浙江坤宇建设有限公司 网站广州seo服务
  • ASP net网站开发资料seo研究中心qq群
  • 有哪些做产品产业链分析的网站软文客
  • 彩票网站建设需要什么2023年时政热点事件
  • 武汉企业建站营销沧州做网络推广的平台
  • 淘宝网站后台怎么做网站排名优化软件联系方式
  • 网站运营预期效果2021谷歌搜索入口
  • 做黑彩网站能赚钱吗2021年网络热点舆论
  • 信息网站建设公关服务
  • 制作网站开发公司企业宣传软文范例
  • 网站只做静态页面安全受到影响查询友情链接
  • 武汉最好的网站建设前十网络营销运营公司
  • 禅城网站建设多少钱深圳网站设计三把火
  • 杭州专业网站制作软文营销方法有哪些
  • 网站开发费用明细产品推广方案
  • 建立com网站深圳网站开发
  • 漯河网站建设电话网页制作app手机版
  • 动态网站cdn福建seo网站
  • excel做网站页面布局企业qq多少钱一年
  • 远洋国际一期官方网站建设谷歌账号
  • 最近时事新闻seo的优点
  • 国外互联网资讯网站福州seo网站管理
  • 南宁网站建设加王道下拉电销系统软件排名
  • 网站开发包括哪些技术想在百度上推广怎么做
  • 做公司网站用哪个公司比较好上海网络seo
  • 网站注册了域名然后怎么做新站点seo联系方式
  • 徐州 网站 备案 哪个公司做的好今天军事新闻最新消息
  • 青海公司网站建设哪家快中国搜索引擎
  • 织梦做中英文网站微信公众号怎么创建
  • 如何建设一个自己的网站百度一下就知道