Commit d3824844 authored by 王业明's avatar 王业明
Browse files

Fix:组件注册,先读原文件第一行,然后根据编码再读一次具体内容

parent f37d9af2
...@@ -420,6 +420,7 @@ public class PythonComponentParser implements PythonComponentConstants ...@@ -420,6 +420,7 @@ public class PythonComponentParser implements PythonComponentConstants
{ {
this.file = file; this.file = file;
BufferedReader br = null; BufferedReader br = null;
charsetName = getCharsetName(file, charsetName);
try try
{ {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName)); br = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
...@@ -503,4 +504,47 @@ public class PythonComponentParser implements PythonComponentConstants ...@@ -503,4 +504,47 @@ public class PythonComponentParser implements PythonComponentConstants
return words; return words;
} }
public String getCharsetName(File file, String charsetName) throws PythonParseExcption
{
BufferedReader br = null;
try
{
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
String line = br.readLine();
int index = -1;
if (line != null) {
if ((index = line.indexOf("# -*- coding:")) > -1) {
int lastIdx = line.lastIndexOf("-*-");
if (lastIdx > -1) {
charsetName = line.substring(index + 13, lastIdx).trim();
} else {
charsetName = line.substring(index + 13).trim();
}
}
}
return charsetName;
}
catch (IOException e)
{
throw new PythonParseExcption(e);
}
finally
{
if (br != null)
{
try
{
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment