write & read a sequence file


write & read a sequence file

 import java.io.IOException;

 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.SequenceFile.Writer;
 import org.apache.hadoop.io.SequenceFile.Reader;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.conf.Configuration;

 public class MySequenceFile {
   static private final String[] DATA =  {
       "this is the first",
       "this is the second",
       "this is the third",
       "this is the forth"
     };  

   public static void main(String[] args) throws IOException {
     Configuration conf = new Configuration();
     FileSystem fs = FileSystem.get(conf);
     Path path = new Path(args[0]);
     IntWritable key = new IntWritable();
     Text value = new Text();

     SequenceFile.Writer writer = null;

     writer = SequenceFile.createWriter(conf, Writer.file(path), Writer.keyClass(key.getClass()), Writer.valueClass(value.getClass()));
     for( int i = 0; i < 1000; i++ ) {
       key.set(i + 1);
       value.set(DATA[i % DATA.length]);
       writer.append(key,value);
     }
     writer.close();
     SequenceFile.Reader reader = new SequenceFile.Reader(conf, Reader.file(path));
     while( reader.next(key, value) ) {
       String syncSeen = reader.syncSeen() ? "*" : "#";
       System.err.println(key + "\t" + value + "\t" + reader.getPosition()+ "\t" + syncSeen);
     }
     reader.close();
   }
 }

write & read a sequence file(基于全新2.2.0API)的更多相关文章

  1. MapReduce——计算温度最大值 (基于全新2.2.0API)

    MapReduce——计算温度最大值 (基于全新2.2.0API) deprecated: Job类的所有Constructors, 新的API用静态方法getInstance(conf)来去的Job ...

  2. write & read a MapFile(基于全新2.2.0API)

    write & read a  MapFile import java.io.IOException; import org.apache.hadoop.io.IntWritable; imp ...

  3. Configurataion Printer(基于全新2.2.0API)

    Configurataion Printer import java.util.Map.Entry; import org.apache.hadoop.conf.Configuration; impo ...

  4. Combine small files to Sequence file

    Combine small files to sequence file or avro files are a good method to feed hadoop. Small files in ...

  5. Predicting effects of noncoding variants with deep learning–based sequence model | 基于深度学习的序列模型预测非编码区变异的影响

    Predicting effects of noncoding variants with deep learning–based sequence model PDF Interpreting no ...

  6. Flume性能测试报告(翻译Flume官方wiki报告)

    因使用flume的时候总是会对其性能有所调研,网上找的要么就是自测的这里找到一份官方wiki的测试报告供大家参考 https://cwiki.apache.org/confluence/display ...

  7. Hadoop IO基于文件的数据结构详解【列式和行式数据结构的存储策略】

    Charles所有关于hadoop的文章参考自hadoop权威指南第四版预览版 大家可以去safari免费阅读其英文预览版.本人也上传了PDF版本在我的资源中可以免费下载,不需要C币,点击这里下载. ...

  8. 基于docker快速搭建hbase集群

    一.概述 HBase是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文"Bigtable:一个结构化数据的分布式存储系统".就像Bigt ...

  9. The Kernel Newbie Corner: Kernel Debugging with proc "Sequence" Files--Part 3

    转载:https://www.linux.com/learn/linux-career-center/44184-the-kernel-newbie-corner-kernel-debugging-w ...

随机推荐

  1. c#解析Josn(解析多个子集,数据,可解析无限级json)

    首先引用 解析类库 using System; using System.Collections.Generic; using System.Linq; using System.Text; name ...

  2. (转)unity开发相关环境(vs、MonoDevelop)windows平台编码问题

    转自: http://www.cnblogs.com/sevenyuan/archive/2012/12/06/2805114.html 1.unity会爆出错误: There are inconsi ...

  3. 点击穿透问题(http://www.tuicool.com/articles/6NfaUnM)

    一.click与300ms延迟 移动浏览器提供一个特殊的功能:双击(double tap)放大 300ms的延迟就来自这里,用户碰触页面之后,需要等待一段时间来判断是不是双击(double tap)动 ...

  4. 从客户端中检测到有潜在危险的 Request.Form 值] 处理办法

    当asp.net提交<>这些字符到aspx页面时,如果未设置 validaterequest="false",就会出现错误:从客户端(<?xml version= ...

  5. CENTOS7 使用网络管理器配置静态IP地址

    CENTOS7 的网络配置和CENTOS6有些不同. 如果你想要使用网络管理器来管理该接口,你可以使用nmtui(网络管理器文本用户界面),它提供了在终端环境中配置配置网络管理器的方式. 在使用nmt ...

  6. 使用Class.getResource和ClassLoader.getResource方法获取文件路径

    自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...

  7. table隔行换色

    以前做表格隔行换色,是在tr上添加不同的背景色,但在程序开发的过程需要做判断,不够方便,而且生成的代码也比较多,现在的需求逐渐修改为JQ去控制简洁的表格去显示隔行换色 <script type= ...

  8. [PHP]htmlentities() 函数

    定义和用法 htmlentities() 函数把字符转换为 HTML 实体. 语法 htmlentities(string,quotestyle,character-set) 参数 描述 string ...

  9. Binding的源和路径

    书上写着:Binding的源也就是数据的源头.Binding对于源的要求很简单-只要他是一个对象!并且通过属性(Property)公开自己的数据,它就可以作为Binding的源了.就像上一篇我写的那个 ...

  10. WPF自定义控件之仿Win8滚动条--ScrollViewer

    1.说明 自己学习WPF不是很久,现将自己做的一些小项目中用到的自定义控件整理出来,方便以后使用,不尽人意之处,还请多多批评与指导,现在就来实现自定义ScrollViewer仿Win8滚动条 2.效果 ...