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. [jquery]基础篇--this与$this区别

    参考: http://www.cnblogs.com/hannover/p/4109779.html 1.JQuery this和$(this)的区别 相信很多刚接触JQuery的人,很多都会对$(t ...

  2. java异常处理练习

    异常的练习: 老师用电脑上课. 开始思考上课中出现的问题. 比如问题是    电脑蓝屏.    电脑冒烟. 要对问题进行描述,封装成对象. 可是当冒烟发生后,出现讲课进度无法继续. 出现了讲师的问题: ...

  3. JS访问Struts 2 ValueStack中的内容

    /* * var myArray = new Array("${vacant[0]}", "${vacant[1]}", "${vacant[2]}& ...

  4. 注意WPF中绑定使用的是引用类型

    绑定(Binding)是WPF提供的一个非常方便的特性,它可以方便的实现一个WPF的MVVM结构. 既可以实现数据驱动UI变化,也可以做到End-user在UI上的修改实现的反映到数据上. 但是有一点 ...

  5. Python和C++交互

    关键字:Python 2.7,VS 2010,swig OS:Win8.1 with update. 1.下载swig:http://www.swig.org/download.html 2.将swi ...

  6. TIBCO ActiveMatrix BPM 生成daa包脚本

    Ant 配置: <?xml version="1.0" encoding="UTF-8" ?> <project name="pro ...

  7. Python OptionParser学习

    from optparse import OptionParser import sys def main(): p = OptionParser() p.add_option('-n','--nam ...

  8. Project not selected to build for this solution configuration.

    Project not selected to build for this solution configuration.   When you upgrade your older solutio ...

  9. WPF中的一些常用类型转换

    1.string和Color的转换: //string转Color (Color)ColorConverter.ConvertFromString((string)str); //Color转stri ...

  10. Java学习--String、StringBuffer与StringBuilder

    String并不是基本数据类型,而是一个对象,并且是不可变的对象.String类为final型的不可被继承,而且通过查看JDK文档会发现几乎每一个修改String对象的操作,实际上都是创建了一个全新的 ...