• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionb1368d21491b39b04896e75bf5ad5a56a8ba64c3 (tree)
Time2018-01-08 22:50:02
Authorshupeluter@hotmail.com <shupeluter@hotm...>
Commitershupeluter@hotmail.com

Log Message

文字コードを設定できるように変更

Change Summary

Incremental Difference

--- a/src/main/java/jp/co/nec/jsight/filecleaner/JavaCleaner.java
+++ b/src/main/java/jp/co/nec/jsight/filecleaner/JavaCleaner.java
@@ -11,25 +11,37 @@ import java.io.File;
1111 import java.io.FileInputStream;
1212 import java.io.FileNotFoundException;
1313 import java.io.FileOutputStream;
14-import java.io.FileWriter;
1514 import java.io.IOException;
15+import java.io.InputStream;
1616 import java.io.InputStreamReader;
1717 import java.io.OutputStreamWriter;
1818 import java.util.List;
1919 import java.util.Map;
20+import java.util.Properties;
2021 import java.util.logging.Level;
2122 import java.util.logging.Logger;
23+import jp.co.nec.jsight.common.JSightException;
2224
2325 /**
2426 *
2527 * @author shupe
2628 */
2729 public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner {
28-
30+ private String inputCode = "UTF-8";
31+ private String outputCode= "UTF-8";
32+
2933 public JavaCleaner(List<Map.Entry> repList) {
3034 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+ }
3142 }
3243
44+
3345 @Override
3446 public void clean(File file) {
3547 super.checkBefore(file);
@@ -44,7 +56,7 @@ public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner {
4456 contents = new StringBuilder();
4557
4658 try {
47- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
59+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),inputCode));
4860
4961 String line = null;
5062
@@ -69,7 +81,7 @@ public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner {
6981
7082 private void recordContents(File file, StringBuilder contents) {
7183 try {
72- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
84+ BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),outputCode));
7385 bw.append(contents.toString());
7486 bw.flush();
7587 } catch (FileNotFoundException ex) {
@@ -79,4 +91,30 @@ public class JavaCleaner extends AbsFileCleaner implements IBasicFileCleaner {
7991 }
8092 }
8193
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+
82120 }
--- a/src/main/java/jp/co/nec/jsight/filecleaner/ReplaceInfoManager.java
+++ b/src/main/java/jp/co/nec/jsight/filecleaner/ReplaceInfoManager.java
@@ -24,31 +24,34 @@ import jp.co.nec.jsight.common.JSightException;
2424 */
2525 public class ReplaceInfoManager {
2626
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";
2833
29- List<Entry> infoList;
30- List<Entry> replacerList;
31-
3234 public ReplaceInfoManager() {
3335 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();
3739 } catch (IOException | JSightException ex) {
3840 Logger.getLogger(ReplaceInfoManager.class.getName()).log(Level.SEVERE, null, ex);
3941 }
4042 }
4143
42-
43- public List getReplaceStrs(){
44+ public List getReplaceStrs() {
4445 return infoList;
4546 }
4647
47- public List getReplacerStrs(){
48+ public List getReplacerStrs() {
4849 return replacerList;
4950 }
51+
52+
5053
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 {
5255 List<Entry> result = new ArrayList();
5356
5457 try (InputStream in = ReplaceInfoManager.class.getResourceAsStream(STR_PROP_FILE_NAME)) {
@@ -61,15 +64,15 @@ public class ReplaceInfoManager {
6164 props.load(in);
6265
6366 String fromInfo = props.getProperty(from);
64- if(fromInfo == null){
65- throw new JSightException(from+"プロパティが設定されていません。");
67+ if (fromInfo == null) {
68+ throw new JSightException(from + "プロパティが設定されていません。");
6669 }
67-
70+
6871 String toInfo = props.getProperty(to);
69- if(toInfo == null){
70- throw new JSightException(to+"プロパティが設定されていません。");
72+ if (toInfo == null) {
73+ throw new JSightException(to + "プロパティが設定されていません。");
7174 }
72-
75+
7376 //,で文字列を分解
7477 String[] fromStrs = fromInfo.split(",");
7578 String[] toStrs = toInfo.split(",");
@@ -82,8 +85,26 @@ public class ReplaceInfoManager {
8285 result.add(new AbstractMap.SimpleEntry<>(fromStrs[i], toStrs[i]));
8386 }
8487 }
85-
88+
8689 return result;
87-
90+
8891 }
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+
89110 }
--- a/src/main/resources/replace.properties
+++ b/src/main/resources/replace.properties
@@ -5,5 +5,11 @@
55 #\u7f6e\u63db\u5bfe\u8c61\u30ad\u30fc\u30ef\u30fc\u30c9
66 rep.from=XX\u30c6\u30b9\u30c8,XX\u30c6\u30b9\u30c8\uff12,\u00d7\u00d7,xx
77 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
810 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
Binary files a/src/test/resources/FileObjectScanerTest/Case3-2.xls and b/src/test/resources/FileObjectScanerTest/Case3-2.xls differ
--- a/src/test/resources/FileObjectScanerTest/Case3_4.java
+++ b/src/test/resources/FileObjectScanerTest/Case3_4.java
@@ -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-
--- a/src/test/resources/JavaCleanerTest/TestTarget1.java
+++ b/src/test/resources/JavaCleanerTest/TestTarget1.java
@@ -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-}
--- a/src/test/resources/replace.properties
+++ b/src/test/resources/replace.properties
@@ -5,5 +5,11 @@
55 #\u7f6e\u63db\u5bfe\u8c61\u30ad\u30fc\u30ef\u30fc\u30c9
66 rep.from=XX\u30c6\u30b9\u30c8,XX\u30c6\u30b9\u30c8\uff12,\u00d7\u00d7,xx
77 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
810 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