2012-10-23 117 views
0

我寫這個Java程序的Hadoop將執行files.The文件的並行指數在日食編譯錯誤:無法映射的字符編碼UTF8

package org.myorg; 

import java.io.*; 
import java.util.*; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.conf.*; 
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapred.*; 
import org.apache.hadoop.util.*; 

public class ParallelIndexation { 


public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { 
    private final static IntWritable zero = new IntWritable(0); 
    private Text word = new Text(); 
    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { 
     String line = value.toString(); 
     int CountComputers; 
     //DataInputStream ConfigFile = new DataInputStream(new FileInputStream("countcomputers.txt")); 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // путь к файлу 
     DataInputStream in = new DataInputStream(fstream); 
     BufferedReader br = new BufferedReader(new InputStreamReader(in)); 
     String result = br.readLine(); // читаем как строку 
     CountComputers = Integer.parseInt(result); // переводим строку в число 
     //CountComputers=ConfigFile.readInt(); 
     in.close(); 
     fstream.close(); 
     ArrayList<String> paths = new ArrayList<String>(); 
     StringTokenizer tokenizer = new StringTokenizer(line, "\n"); 
     while (tokenizer.hasMoreTokens()) 
     { 
      paths.add(tokenizer.nextToken()); 
     } 
     String[] ConcatPaths= new String[CountComputers]; 
     int NumberOfElementConcatPaths=0; 
     if (paths.size()%CountComputers==0) 
     { 
      for (int i=0; i<CountComputers; i++) 
      { 
       ConcatPaths[i]=paths.get(NumberOfElementConcatPaths); 
       NumberOfElementConcatPaths+=paths.size()/CountComputers; 
       for (int j=1; j<paths.size()/CountComputers; j++) 
       { 
        ConcatPaths[i]+="\n"+paths.get(i*paths.size()/CountComputers+j); 
       } 
      } 
     } 
     else 
     { 
      NumberOfElementConcatPaths=0; 
      for (int i=0; i<paths.size()%CountComputers; i++) 
      { 
       ConcatPaths[i]=paths.get(NumberOfElementConcatPaths); 
       NumberOfElementConcatPaths+=paths.size()/CountComputers+1;    
       for (int j=1; j<paths.size()/CountComputers+1; j++) 
       { 
        ConcatPaths[i]+="\n"+paths.get(i*(paths.size()/CountComputers+1)+j); 
       }   
      } 
      for (int k=paths.size()%CountComputers; k<CountComputers; k++) 
      { 
       ConcatPaths[k]=paths.get(NumberOfElementConcatPaths); 
       NumberOfElementConcatPaths+=paths.size()/CountComputers;     
       for (int j=1; j<paths.size()/CountComputers; j++) 
       { 
        ConcatPaths[k]+="\n"+paths.get((k-paths.size()%CountComputers)*paths.size()/CountComputers+paths.size()%CountComputers*(paths.size()/CountComputers+1)+j); 
       }     
      } 
     } 
     //CountComputers=ConfigFile.readInt(); 
     for (int i=0; i<ConcatPaths.length; i++) 
     { 
      word.set(ConcatPaths[i]); 
      output.collect(word, zero); 
     } 
    } 
} 



public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> { 
    public native long Traveser(String Path); 
    public native void Configure(String Path); 
    public void reduce(Text key, IntWritable value, OutputCollector<Text, LongWritable> output, Reporter reporter) throws IOException { 
     long count; 
     String line = key.toString(); 
     ArrayList<String> ProcessedPaths = new ArrayList<String>(); 
     StringTokenizer tokenizer = new StringTokenizer(line, "\n"); 
     while (tokenizer.hasMoreTokens()) 
     { 
      ProcessedPaths.add(tokenizer.nextToken()); 
     }  
     Configure("/etc/nsindexer.conf"); 
     for (int i=0; i<ProcessedPaths.size(); i++) 
     { 
      count=Traveser(ProcessedPaths.get(i)); 
     } 
     output.collect(key, new LongWritable(count)); 
     } 
    static 
    { 
     System.loadLibrary("nativelib"); 
    } 
} 

public static void main(String[] args) throws Exception { 
     JobConf conf = new JobConf(ParallelIndexation.class); 
     conf.setJobName("parallelindexation"); 
     conf.setOutputKeyClass(Text.class); 
     conf.setOutputValueClass(LongWritable.class); 
     conf.setMapperClass(Map.class); 
     conf.setCombinerClass(Reduce.class); 
     conf.setReducerClass(Reduce.class); 
     conf.setInputFormat(TextInputFormat.class); 
     conf.setOutputFormat(TextOutputFormat.class); 
     FileInputFormat.setInputPaths(conf, new Path(args[0])); 
     FileOutputFormat.setOutputPath(conf, new Path(args[1])); 
     JobClient.runJob(conf); 
    } 
} 

創建爲編輯在Nexenta的Illumos的結果操作系統(Solaris)的隊的手段

javac -classpath hadoop-examples-1.0.1.jar -d folder/classes folder/src/ParallelIndexation.java, 

接收以下錯誤

folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                        ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                        ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                        ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                         ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                         ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                          ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                          ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                          ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                          ^
folder/src/ParallelIndexation.java:23: error: unmappable character for encoding UTF8 
     FileInputStream fstream = new FileInputStream("/usr/countcomputers.txt"); // ���� � ����� 
                           ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
             ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
             ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
              ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
              ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
              ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
              ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
               ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
               ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
               ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
                ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
                ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
                ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
                 ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
                 ^
folder/src/ParallelIndexation.java:26: error: unmappable character for encoding UTF8 
     String result = br.readLine(); // ������ ��� ������ 
                 ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                 ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                 ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                 ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                 ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                  ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                  ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                  ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                   ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                   ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                   ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                   ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                    ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                    ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                    ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                     ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                     ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                     ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                      ^
folder/src/ParallelIndexation.java:27: error: unmappable character for encoding UTF8 
     CountComputers = Integer.parseInt(result); // ��������� ������ � ����� 
                      ^
46 errors 

如何在eclipse中更改UTF8的編碼?

+0

檢查文件的編碼我猜你的讚揚是麻煩之源 – kirschmichel

回答

0

在Eclipse中,您可以設置文本文件編碼在三個地方:

  • 在工作區級別:首選項/常規/工作區/文本文件編碼
  • 在項目層面上:地產(項目)/資源/文本文件編碼
  • 在文件級別:地產(對文件)/資源/文本文件編碼

我建議在工作區和項目水平,如果將其設置只有在文件級別需要時。

設置文件編碼並不真正轉換文件本身。您可能需要使用單獨的工具(例如iconv)。

+1

有很少一個很好的理由來設置這個在文件級:一期工程內的所有文件應使用相同的編碼, 越多越好。 –

+0

是的,你說得對。我已經更新了我的建議。 – Codo

+0

如果你有幾個要轉換的文件,Notepad ++(http://notepad-plus-plus.org/)可以爲你做,如果它是一個整個項目,我同意'iconv'路線。 –

0

Java 6爲可映射字符提供「警告」。

Java 7爲可映射字符提供「錯誤」,並失敗。

file -bi [filename] 
相關問題