/*$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;
*/
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;
}
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() {
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);
}
}