From ca3f9963c62d4b6268de948d05eb5f73e1827554 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sat, 16 Apr 2016 21:01:05 +0000 Subject: [PATCH] Addressbook: More cleanups --- .../net/i2p/addressbook/ConfigIterator.java | 4 +++- .../src/net/i2p/addressbook/ConfigParser.java | 4 +++- .../java/src/net/i2p/addressbook/Log.java | 2 ++ .../net/i2p/addressbook/SubscriptionList.java | 23 +++++++++++-------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/apps/addressbook/java/src/net/i2p/addressbook/ConfigIterator.java b/apps/addressbook/java/src/net/i2p/addressbook/ConfigIterator.java index aa67dfaacd..df13332f2a 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/ConfigIterator.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/ConfigIterator.java @@ -71,7 +71,9 @@ class ConfigIterator implements Iterator<Map.Entry<String, String>>, Closeable { String inputLine; while ((inputLine = input.readLine()) != null) { inputLine = ConfigParser.stripComments(inputLine); - String[] splitLine = DataHelper.split(inputLine, "="); + if (inputLine.length() == 0) + continue; + String[] splitLine = DataHelper.split(inputLine, "=", 2); if (splitLine.length == 2) { next = new ConfigEntry(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim()); return true; diff --git a/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java b/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java index 38985d00ea..58b08db535 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java @@ -93,7 +93,9 @@ class ConfigParser { String inputLine; while ((inputLine = input.readLine()) != null) { inputLine = stripComments(inputLine); - String[] splitLine = DataHelper.split(inputLine, "="); + if (inputLine.length() == 0) + continue; + String[] splitLine = DataHelper.split(inputLine, "=", 2); if (splitLine.length == 2) { result.put(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim()); } diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Log.java b/apps/addressbook/java/src/net/i2p/addressbook/Log.java index c6798f5647..501ab5cacf 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Log.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Log.java @@ -74,7 +74,9 @@ class Log { * * @return The File that the log is writing to. */ +/**** public File getFile() { return this.file; } +****/ } diff --git a/apps/addressbook/java/src/net/i2p/addressbook/SubscriptionList.java b/apps/addressbook/java/src/net/i2p/addressbook/SubscriptionList.java index d9135e4ff5..1bca241403 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/SubscriptionList.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/SubscriptionList.java @@ -24,6 +24,7 @@ package net.i2p.addressbook; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -80,17 +81,17 @@ class SubscriptionList implements Iterable<AddressBook> { try { etags = ConfigParser.parse(etagsFile); } catch (IOException exp) { - etags = new HashMap<String, String>(); + etags = Collections.<String, String>emptyMap(); } try { lastModified = ConfigParser.parse(lastModifiedFile); } catch (IOException exp) { - lastModified = new HashMap<String, String>(); + lastModified = Collections.<String, String>emptyMap(); } try { lastFetched = ConfigParser.parse(lastFetchedFile); } catch (IOException exp) { - lastFetched = new HashMap<String, String>(); + lastFetched = Collections.<String, String>emptyMap(); } for (String location : locations) { this.subscriptions.add(new Subscription(location, etags.get(location), @@ -117,9 +118,10 @@ class SubscriptionList implements Iterable<AddressBook> { * won't be read back correctly; the '=' should be escaped. */ public void write() { - Map<String, String> etags = new HashMap<String, String>(); - Map<String, String> lastModified = new HashMap<String, String>(); - Map<String, String> lastFetched = new HashMap<String, String>(); + int sz = subscriptions.size(); + Map<String, String> etags = new HashMap<String, String>(sz); + Map<String, String> lastModified = new HashMap<String, String>(sz); + Map<String, String> lastFetched = new HashMap<String, String>(sz); for (Subscription sub : this.subscriptions) { if (sub.getEtag() != null) { etags.put(sub.getLocation(), sub.getEtag()); @@ -127,13 +129,16 @@ class SubscriptionList implements Iterable<AddressBook> { if (sub.getLastModified() != null) { lastModified.put(sub.getLocation(), sub.getLastModified()); } - lastFetched.put(sub.getLocation(), "" + sub.getLastFetched()); + lastFetched.put(sub.getLocation(), Long.toString(sub.getLastFetched())); } try { ConfigParser.write(etags, this.etagsFile); + } catch (IOException exp) {} + try { ConfigParser.write(lastModified, this.lastModifiedFile); + } catch (IOException exp) {} + try { ConfigParser.write(lastFetched, this.lastFetchedFile); - } catch (IOException exp) { - } + } catch (IOException exp) {} } } -- GitLab