write & read a  MapFile


 import java.io.IOException;

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

 public class MyMapFile {

   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);
     String uri = args[0];

     IntWritable key = new IntWritable();
     Text val = new Text();

     MapFile.Writer writer = new MapFile.Writer(conf, new Path(uri), Writer.keyClass(key.getClass()), Writer.valueClass(val.getClass())); 

     for( int i = 0; i < 10; i++ ) {
       key.set( i + 1 );
       val.set(DATA[ i % DATA.length ]);
       writer.append(key, val);
     }
     writer.close();

     MapFile.Reader reader = new MapFile.Reader(new Path(uri), conf);

     while( reader.next(key, val) ){
       System.out.println( key + "\t" + val );
     }
     reader.close();
   }
 }

最新文章

  1. 21-React的学习
  2. sed 命令使用
  3. MySQL Error Handling in Stored Procedures
  4. EF深入系列--细节
  5. Counting Sequences_线段树***
  6. Xamarin Android布局文件没有智能提示
  7. Linux下Openssl的安装全过程
  8. java 不寻常的问题 No bean named &amp;#39;sessionFactory&amp;#39; is defined 和 initialize a collection of role
  9. 详解CockroachDB事务处理系统
  10. php工作两年了。。。
  11. TF-IDF_MapReduceJava代码实现思路
  12. 使用Keepalived配置主从热备实现Nginx高可用(HA)
  13. Java 容器 &amp; 泛型:五、HashMap 和 TreeMap的自白
  14. idea护眼设置
  15. OGG实现两台Oracle数据库的同步
  16. PyQt5初级教程(一)
  17. 向jupyter notebook加入Anaconda3中已添加的虚拟环境kernel
  18. 02 如何创建线程 线程并发与synchornized
  19. Eclipse安装php插件phpeclipse(转)
  20. 2-功能1:基于用户认证组件和Ajax实现登录验证(图片验证码)

热门文章

  1. hibernate案例 测试代码
  2. 九度OJ 1505 两个链表的第一个公共结点 【数据结构】
  3. HTML5之地理信息应用 获取自己的位置
  4. slabs.c
  5. Struts2 Annotation 默认返回Tiles2布局
  6. HTML meta viewport属性说明
  7. Popen No such file or directory 错误
  8. python中functools.wraps装饰器的作用
  9. vim emmet配置
  10. 开发设计模式(六)多例模式(Multition Pattern)