/*$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 String getUrl() {
return url;
}
+
+ @Override
+ public String toString() {
+ return getUrl() + ", " + getNumber();
+ }
}
private static Log log = LogFactory.getLog(Config.class);
private static Config instance;
*/
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);
+ if (!CONFIG_FILE.exists()) {
+ createNewConfigFile(CONFIG_FILE);
+ result = true;
+ log.info("コンフィグファイルを作成しました: " + CONFIG_FILE.getCanonicalPath());
+ }
+ if (!FEEDURL_FILE.exists()) {
+ InputStream resource = null;
+ try {
+ resource = ClassLoader.getSystemResourceAsStream("resources/" + FEEDURL_NAME);
+ createNewFeedFile(resource, FEEDURL_FILE);
result = true;
log.info("FEED URLファイルを作成しました: " + FEEDURL_FILE.getCanonicalPath());
+ } finally {
+ if (resource != null) {
+ resource.close();
+ }
}
- } catch (URISyntaxException ex) {
- throw new IOException(ex);
}
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() {
// }
//
- public String[] getDownLoadMyList() {
+ public List<String> getDownLoadMyList() {
+ List<String> list = new ArrayList<String>();
String res = properties.getProperty(P_DOWNLOAD_MYLIST);
String[] nums = res.split(",");
for (int i = 0; i < nums.length; i++) {
- nums[i] = nums[i].trim();
+ String text = nums[i].trim();
+ if (!text.isEmpty()) {
+ list.add(text);
+ }
}
- return nums;
+ return list;
}
public List<NicoFeed> getNicoFeeds() {
- throw new UnsupportedOperationException("Not yet implemented");
+ List<NicoFeed> list = new ArrayList<NicoFeed>();
+ try {
+ List lines = FileUtils.readLines(FEEDURL_FILE, getEncoding());
+ for (Object line : lines) {
+ final String str = line.toString();
+ if (str.isEmpty() || str.startsWith("#")) {
+ // 空行, コメント行はスキップ.
+ continue;
+ }
+
+ String[] values = str.split(",");
+ NicoFeed feed = new NicoFeed(values[0].trim(), Integer.parseInt(values[1].trim()));
+ list.add(feed);
+ }
+ } catch (IOException ex) {
+ log.error("ファイルが見つかりません: " + FEEDURL_FILE);
+ }
+ return list;
}
}