2014-11-05 45 views
0

我使用的是hadoop 1.0.3(我現在無法真正升級,稍後再說。) 我的HDFS中有大約100張圖像我試圖將它們組合成一個單一的sequencefile(默認的無壓縮等)hadoop-1.0.3 sequenceFile.Writer覆蓋,而不是將圖像添加到序列文件中

這裏是我的代碼:

  FSDataInputStream in = null; 
       BytesWritable value = new BytesWritable(); 
       Text key = new Text(); 
       Path inpath = new Path(fs.getHomeDirectory(),"/user/hduser/input"); 
       Path seq_path = new Path(fs.getHomeDirectory(),"/user/hduser/output/file.seq"); 
       FileStatus[] files = fs.listStatus(inpath); 
       SequenceFile.Writer writer = null; 
       for(FileStatus fileStatus : files){ 
          inpath = fileStatus.getPath(); 
       try { 

          in = fs.open(inpath); 
          byte bufffer[] = new byte[in.available()]; 
          in.read(bufffer); 
          writer = SequenceFile.createWriter(fs,conf,seq_path,key.getClass(),value.getClass()); 
          writer.append(new Text(inpath.getName()), new BytesWritable(bufffer)); 



       }catch (Exception e) { 
        System.out.println("Exception MESSAGES = "+e.getMessage()); 
        e.printStackTrace(); 
       }} 

這只是通過輸入的所有文件去/並逐個並將其附加。 然而這只是覆蓋我的序列文件,而不是附加它,我只看到sequencefile中的最後一個圖像。

注意我沒有在for循環結束前關閉作者,任何人都可以幫助我這個請。 我不確定如何追加圖像?

回答

0

你的主要問題是與以下行:

writer = SequenceFile.createWriter(fs, conf, seq_path, key.getClass(), value.getClass()); 

這是for內,創建各個循環中的新writer。它將替換路徑爲seq_path的前一個文件。因此只有最後一張圖片可用。

將其拉出循環,問題應該消失。

相關問題