OSDN Git Service

jarからファイルを取り出すのにgetSystemResourceが使えなかったため, getSystemResourceAsStreamに変更.
authoryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sun, 24 May 2009 07:28:02 +0000 (07:28 +0000)
committeryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sun, 24 May 2009 07:28:02 +0000 (07:28 +0000)
git-svn-id: http://192.168.11.7/svn/repository/NicoBrowserBranches/release_20090323/NicoBrowser@129 bdf3b611-c98c-6041-8292-703d9c9adbe7

src/nicobrowser/Config.java

index 7ed98be..0333237 100644 (file)
@@ -1,9 +1,13 @@
 /*$Id$*/
 package nicobrowser;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -67,20 +71,17 @@ public final class Config {
      */
     public static boolean createNewConfigFiles() throws IOException {
         boolean result = false;
-        try {
-            if (!CONFIG_FILE.exists()) {
-                createNewConfigFile(CONFIG_FILE);
-                result = true;
-                log.info("コンフィグファイルを作成しました: " + CONFIG_FILE.getCanonicalPath());
-            }
-            if (!FEEDURL_FILE.exists()) {
-                URL resource = ClassLoader.getSystemResource("resources/" + FEEDURL_NAME);
-                createNewFeedFile(new File(resource.toURI()), FEEDURL_FILE);
-                result = true;
-                log.info("FEED URLファイルを作成しました: " + FEEDURL_FILE.getCanonicalPath());
-            }
-        } catch (URISyntaxException ex) {
-            throw new IOException(ex);
+        if (!CONFIG_FILE.exists()) {
+            createNewConfigFile(CONFIG_FILE);
+            result = true;
+            log.info("コンフィグファイルを作成しました: " + CONFIG_FILE.getCanonicalPath());
+        }
+        if (!FEEDURL_FILE.exists()) {
+            InputStream resource = null;
+            resource = ClassLoader.getSystemResourceAsStream("resources/" + FEEDURL_NAME);
+            createNewFeedFile(resource, FEEDURL_FILE);
+            result = true;
+            log.info("FEED URLファイルを作成しました: " + FEEDURL_FILE.getCanonicalPath());
         }
         return result;
     }
@@ -111,9 +112,17 @@ public final class Config {
         FileUtils.writeLines(file, props);
     }
 
-    private static void createNewFeedFile(File resource, File dest) throws IOException {
-        List text = FileUtils.readLines(resource, "UTF-8");
-        FileUtils.writeLines(dest, text);
+    private static void createNewFeedFile(InputStream resource, File dest) throws IOException {
+        List<String> list = new ArrayList<String>();
+        BufferedReader br = new BufferedReader(new InputStreamReader(resource, "UTF-8"));
+        while (true) {
+            String text = br.readLine();
+            if (text == null) {
+                break;
+            }
+            list.add(text);
+        }
+        FileUtils.writeLines(dest, list);
     }
 
     private Config() {
@@ -218,7 +227,7 @@ public final class Config {
         String[] nums = res.split(",");
         for (int i = 0; i < nums.length; i++) {
             String text = nums[i].trim();
-            if(!text.isEmpty()){
+            if (!text.isEmpty()) {
                 list.add(text);
             }
         }