Revision | b1368d21491b39b04896e75bf5ad5a56a8ba64c3 (tree) |
---|---|
Time | 2018-01-08 22:50:02 |
Author | shupeluter@hotmail.com <shupeluter@hotm...> |
Commiter | shupeluter@hotmail.com |
文字コードを設定できるように変更
@@ -11,25 +11,37 @@ import java.io.File; | ||
11 | 11 | import java.io.FileInputStream; |
12 | 12 | import java.io.FileNotFoundException; |
13 | 13 | import java.io.FileOutputStream; |
14 | -import java.io.FileWriter; | |
15 | 14 | import java.io.IOException; |
15 | +import java.io.InputStream; | |
16 | 16 | import java.io.InputStreamReader; |
17 | 17 | import java.io.OutputStreamWriter; |
18 | 18 | import java.util.List; |
19 | 19 | import java.util.Map; |
20 | +import java.util.Properties; | |
20 | 21 | import java.util.logging.Level; |
21 | 22 | import java.util.logging.Logger; |
23 | +import jp.co.nec.jsight.common.JSightException; | |
22 | 24 | |
23 | 25 | /** |
24 | 26 | * |
25 | 27 | * @author shupe |
26 | 28 | */ |
27 | 29 | public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner { |
28 | - | |
30 | + private String inputCode = "UTF-8"; | |
31 | + private String outputCode= "UTF-8"; | |
32 | + | |
29 | 33 | public JavaCleaner(List<Map.Entry> repList) { |
30 | 34 | super(repList); |
35 | + try { | |
36 | + this.loadCharCode(); | |
37 | + } catch (IOException ex) { | |
38 | + Logger.getLogger(JavaCleaner.class.getName()).log(Level.SEVERE, null, ex); | |
39 | + } catch (Exception ex) { | |
40 | + Logger.getLogger(JavaCleaner.class.getName()).log(Level.SEVERE, null, ex); | |
41 | + } | |
31 | 42 | } |
32 | 43 | |
44 | + | |
33 | 45 | @Override |
34 | 46 | public void clean(File file) { |
35 | 47 | super.checkBefore(file); |
@@ -44,7 +56,7 @@ public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner { | ||
44 | 56 | contents = new StringBuilder(); |
45 | 57 | |
46 | 58 | try { |
47 | - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); | |
59 | + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),inputCode)); | |
48 | 60 | |
49 | 61 | String line = null; |
50 | 62 |
@@ -69,7 +81,7 @@ public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner { | ||
69 | 81 | |
70 | 82 | private void recordContents(File file, StringBuilder contents) { |
71 | 83 | try { |
72 | - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); | |
84 | + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),outputCode)); | |
73 | 85 | bw.append(contents.toString()); |
74 | 86 | bw.flush(); |
75 | 87 | } catch (FileNotFoundException ex) { |
@@ -79,4 +91,30 @@ public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner { | ||
79 | 91 | } |
80 | 92 | } |
81 | 93 | |
94 | + | |
95 | + private void loadCharCode() throws IOException, Exception { | |
96 | + try (InputStream in = ReplaceInfoManager.class.getResourceAsStream(ReplaceInfoManager.STR_PROP_FILE_NAME)) { | |
97 | + | |
98 | + if (in == null) { | |
99 | + throw new FileNotFoundException(ReplaceInfoManager.STR_PROP_FILE_NAME + "が見つかりません。"); | |
100 | + } | |
101 | + | |
102 | + Properties props = new Properties(); | |
103 | + props.load(in); | |
104 | + this.outputCode = props.getProperty("output.code"); | |
105 | + if(outputCode == null){ | |
106 | + throw new JSightException("プロパティ、output.codeが設定されていません。"); | |
107 | + } | |
108 | + this.inputCode = props.getProperty("input.code"); | |
109 | + if(inputCode == null){ | |
110 | + throw new JSightException("プロパティ、input.codeが設定されていません。"); | |
111 | + } | |
112 | + } | |
113 | + | |
114 | + } | |
115 | + | |
116 | + private Exception JSightException(String プロパティoutcodeが設定されていません) { | |
117 | + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
118 | + } | |
119 | + | |
82 | 120 | } |
@@ -24,31 +24,34 @@ import jp.co.nec.jsight.common.JSightException; | ||
24 | 24 | */ |
25 | 25 | public class ReplaceInfoManager { |
26 | 26 | |
27 | - private final String STR_PROP_FILE_NAME = "/replace.properties"; | |
27 | + static final String STR_PROP_FILE_NAME = "/replace.properties"; | |
28 | + | |
29 | + private List<Entry> infoList; | |
30 | + private List<Entry> replacerList; | |
31 | + private String inputCharCode = "UTF-8"; | |
32 | + private String outputCharCode = "UTF-8"; | |
28 | 33 | |
29 | - List<Entry> infoList; | |
30 | - List<Entry> replacerList; | |
31 | - | |
32 | 34 | public ReplaceInfoManager() { |
33 | 35 | try { |
34 | - infoList = loadRelaceInfo("rep.from","rep.to"); | |
35 | - replacerList = loadRelaceInfo("rep.id","rep.class"); | |
36 | - | |
36 | + infoList = loadRelaceInfo("rep.from", "rep.to"); | |
37 | + replacerList = loadRelaceInfo("rep.id", "rep.class"); | |
38 | + //loadCharCode(); | |
37 | 39 | } catch (IOException | JSightException ex) { |
38 | 40 | Logger.getLogger(ReplaceInfoManager.class.getName()).log(Level.SEVERE, null, ex); |
39 | 41 | } |
40 | 42 | } |
41 | 43 | |
42 | - | |
43 | - public List getReplaceStrs(){ | |
44 | + public List getReplaceStrs() { | |
44 | 45 | return infoList; |
45 | 46 | } |
46 | 47 | |
47 | - public List getReplacerStrs(){ | |
48 | + public List getReplacerStrs() { | |
48 | 49 | return replacerList; |
49 | 50 | } |
51 | + | |
52 | + | |
50 | 53 | |
51 | - private List<Entry> loadRelaceInfo(String from,String to) throws FileNotFoundException, IOException, JSightException { | |
54 | + private List<Entry> loadRelaceInfo(String from, String to) throws FileNotFoundException, IOException, JSightException { | |
52 | 55 | List<Entry> result = new ArrayList(); |
53 | 56 | |
54 | 57 | try (InputStream in = ReplaceInfoManager.class.getResourceAsStream(STR_PROP_FILE_NAME)) { |
@@ -61,15 +64,15 @@ public class ReplaceInfoManager { | ||
61 | 64 | props.load(in); |
62 | 65 | |
63 | 66 | String fromInfo = props.getProperty(from); |
64 | - if(fromInfo == null){ | |
65 | - throw new JSightException(from+"プロパティが設定されていません。"); | |
67 | + if (fromInfo == null) { | |
68 | + throw new JSightException(from + "プロパティが設定されていません。"); | |
66 | 69 | } |
67 | - | |
70 | + | |
68 | 71 | String toInfo = props.getProperty(to); |
69 | - if(toInfo == null){ | |
70 | - throw new JSightException(to+"プロパティが設定されていません。"); | |
72 | + if (toInfo == null) { | |
73 | + throw new JSightException(to + "プロパティが設定されていません。"); | |
71 | 74 | } |
72 | - | |
75 | + | |
73 | 76 | //,で文字列を分解 |
74 | 77 | String[] fromStrs = fromInfo.split(","); |
75 | 78 | String[] toStrs = toInfo.split(","); |
@@ -82,8 +85,26 @@ public class ReplaceInfoManager { | ||
82 | 85 | result.add(new AbstractMap.SimpleEntry<>(fromStrs[i], toStrs[i])); |
83 | 86 | } |
84 | 87 | } |
85 | - | |
88 | + | |
86 | 89 | return result; |
87 | - | |
90 | + | |
88 | 91 | } |
92 | + | |
93 | + //ToDo 本来はここに作りたい | |
94 | + /*private void loadCharCode() throws IOException { | |
95 | + try (InputStream in = ReplaceInfoManager.class.getResourceAsStream(STR_PROP_FILE_NAME)) { | |
96 | + | |
97 | + if (in == null) { | |
98 | + throw new FileNotFoundException(STR_PROP_FILE_NAME + "が見つかりません。"); | |
99 | + } | |
100 | + | |
101 | + Properties props = new Properties(); | |
102 | + props.load(in); | |
103 | + this.outputCharCode = props.getProperty("out.code"); | |
104 | + this.inputCharCode = props.getProperty("input.code"); | |
105 | + } | |
106 | + | |
107 | + }*/ | |
108 | + | |
109 | + | |
89 | 110 | } |
@@ -5,5 +5,11 @@ | ||
5 | 5 | #\u7f6e\u63db\u5bfe\u8c61\u30ad\u30fc\u30ef\u30fc\u30c9 |
6 | 6 | rep.from=XX\u30c6\u30b9\u30c8,XX\u30c6\u30b9\u30c8\uff12,\u00d7\u00d7,xx |
7 | 7 | rep.to=\u3007\u3007\u30c6\u30b9\u30c8,\u3007\u3007\u30c6\u30b9\u30c8\uff12,\u3007\u3007,oo |
8 | + | |
9 | +#\u30d5\u30a1\u30a4\u30eb\u306e\u7a2e\u985e\u3068\u30cf\u30f3\u30c9\u30e9 | |
8 | 10 | rep.id=java,xls |
9 | -rep.class=jp.co.nec.jsight.filecleaner.JavaCleaner,jp.co.nec.jsight.filecleaner.ExcelCleaner | |
\ No newline at end of file | ||
11 | +rep.class=jp.co.nec.jsight.filecleaner.JavaCleaner,jp.co.nec.jsight.filecleaner.ExcelCleaner | |
12 | + | |
13 | +#\u30c6\u30ad\u30b9\u30c8\u7cfb\u30d5\u30a1\u30a4\u30eb\u306e\u51fa\u529b\u3001\u5165\u529b\u6587\u5b57\u30b3\u30fc\u30c9 | |
14 | +output.code=UTF-8 | |
15 | +input.code=UTF-8 | |
\ No newline at end of file |
@@ -1,24 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package FileObjectScanerTest; | |
7 | - | |
8 | -/** | |
9 | - * | |
10 | - * @author shupe | |
11 | - */ | |
12 | -public class Case3_4 { | |
13 | - | |
14 | - public Case3_4() { | |
15 | - } | |
16 | - public void testXX(){ | |
17 | - | |
18 | - } | |
19 | - | |
20 | - public void testoo(){ | |
21 | - //�? | |
22 | - } | |
23 | -} | |
24 | - |
@@ -1,23 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package TestTarget1; | |
7 | - | |
8 | -/** | |
9 | - * | |
10 | - * @author shupe | |
11 | - */ | |
12 | -public class TestTarget1 { | |
13 | - | |
14 | - public TestTarget1() { | |
15 | - } | |
16 | - public void testXX(){ | |
17 | - | |
18 | - } | |
19 | - | |
20 | - public void testoo(){ | |
21 | - //テ療? | |
22 | - } | |
23 | -} |
@@ -5,5 +5,11 @@ | ||
5 | 5 | #\u7f6e\u63db\u5bfe\u8c61\u30ad\u30fc\u30ef\u30fc\u30c9 |
6 | 6 | rep.from=XX\u30c6\u30b9\u30c8,XX\u30c6\u30b9\u30c8\uff12,\u00d7\u00d7,xx |
7 | 7 | rep.to=\u3007\u3007\u30c6\u30b9\u30c8,\u3007\u3007\u30c6\u30b9\u30c8\uff12,\u3007\u3007,oo |
8 | + | |
9 | +#\u30d5\u30a1\u30a4\u30eb\u306e\u7a2e\u985e\u3068\u30cf\u30f3\u30c9\u30e9 | |
8 | 10 | rep.id=java,xls |
9 | -rep.class=jp.co.nec.jsight.filecleaner.JavaCleaner,jp.co.nec.jsight.filecleaner.ExcelCleaner | |
\ No newline at end of file | ||
11 | +rep.class=jp.co.nec.jsight.filecleaner.JavaCleaner,jp.co.nec.jsight.filecleaner.ExcelCleaner | |
12 | + | |
13 | +#\u30c6\u30ad\u30b9\u30c8\u7cfb\u30d5\u30a1\u30a4\u30eb\u306e\u51fa\u529b\u3001\u5165\u529b\u6587\u5b57\u30b3\u30fc\u30c9 | |
14 | +output.code=UTF-8 | |
15 | +input.code=UTF-8 | |
\ No newline at end of file |