I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit ca3f9963 authored by zzz's avatar zzz
Browse files

Addressbook: More cleanups

parent ebbf7f23
No related branches found
No related tags found
No related merge requests found
...@@ -71,7 +71,9 @@ class ConfigIterator implements Iterator<Map.Entry<String, String>>, Closeable { ...@@ -71,7 +71,9 @@ class ConfigIterator implements Iterator<Map.Entry<String, String>>, Closeable {
String inputLine; String inputLine;
while ((inputLine = input.readLine()) != null) { while ((inputLine = input.readLine()) != null) {
inputLine = ConfigParser.stripComments(inputLine); inputLine = ConfigParser.stripComments(inputLine);
String[] splitLine = DataHelper.split(inputLine, "="); if (inputLine.length() == 0)
continue;
String[] splitLine = DataHelper.split(inputLine, "=", 2);
if (splitLine.length == 2) { if (splitLine.length == 2) {
next = new ConfigEntry(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim()); next = new ConfigEntry(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim());
return true; return true;
......
...@@ -93,7 +93,9 @@ class ConfigParser { ...@@ -93,7 +93,9 @@ class ConfigParser {
String inputLine; String inputLine;
while ((inputLine = input.readLine()) != null) { while ((inputLine = input.readLine()) != null) {
inputLine = stripComments(inputLine); inputLine = stripComments(inputLine);
String[] splitLine = DataHelper.split(inputLine, "="); if (inputLine.length() == 0)
continue;
String[] splitLine = DataHelper.split(inputLine, "=", 2);
if (splitLine.length == 2) { if (splitLine.length == 2) {
result.put(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim()); result.put(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim());
} }
......
...@@ -74,7 +74,9 @@ class Log { ...@@ -74,7 +74,9 @@ class Log {
* *
* @return The File that the log is writing to. * @return The File that the log is writing to.
*/ */
/****
public File getFile() { public File getFile() {
return this.file; return this.file;
} }
****/
} }
...@@ -24,6 +24,7 @@ package net.i2p.addressbook; ...@@ -24,6 +24,7 @@ package net.i2p.addressbook;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -80,17 +81,17 @@ class SubscriptionList implements Iterable<AddressBook> { ...@@ -80,17 +81,17 @@ class SubscriptionList implements Iterable<AddressBook> {
try { try {
etags = ConfigParser.parse(etagsFile); etags = ConfigParser.parse(etagsFile);
} catch (IOException exp) { } catch (IOException exp) {
etags = new HashMap<String, String>(); etags = Collections.<String, String>emptyMap();
} }
try { try {
lastModified = ConfigParser.parse(lastModifiedFile); lastModified = ConfigParser.parse(lastModifiedFile);
} catch (IOException exp) { } catch (IOException exp) {
lastModified = new HashMap<String, String>(); lastModified = Collections.<String, String>emptyMap();
} }
try { try {
lastFetched = ConfigParser.parse(lastFetchedFile); lastFetched = ConfigParser.parse(lastFetchedFile);
} catch (IOException exp) { } catch (IOException exp) {
lastFetched = new HashMap<String, String>(); lastFetched = Collections.<String, String>emptyMap();
} }
for (String location : locations) { for (String location : locations) {
this.subscriptions.add(new Subscription(location, etags.get(location), this.subscriptions.add(new Subscription(location, etags.get(location),
...@@ -117,9 +118,10 @@ class SubscriptionList implements Iterable<AddressBook> { ...@@ -117,9 +118,10 @@ class SubscriptionList implements Iterable<AddressBook> {
* won't be read back correctly; the '=' should be escaped. * won't be read back correctly; the '=' should be escaped.
*/ */
public void write() { public void write() {
Map<String, String> etags = new HashMap<String, String>(); int sz = subscriptions.size();
Map<String, String> lastModified = new HashMap<String, String>(); Map<String, String> etags = new HashMap<String, String>(sz);
Map<String, String> lastFetched = new HashMap<String, String>(); Map<String, String> lastModified = new HashMap<String, String>(sz);
Map<String, String> lastFetched = new HashMap<String, String>(sz);
for (Subscription sub : this.subscriptions) { for (Subscription sub : this.subscriptions) {
if (sub.getEtag() != null) { if (sub.getEtag() != null) {
etags.put(sub.getLocation(), sub.getEtag()); etags.put(sub.getLocation(), sub.getEtag());
...@@ -127,13 +129,16 @@ class SubscriptionList implements Iterable<AddressBook> { ...@@ -127,13 +129,16 @@ class SubscriptionList implements Iterable<AddressBook> {
if (sub.getLastModified() != null) { if (sub.getLastModified() != null) {
lastModified.put(sub.getLocation(), sub.getLastModified()); lastModified.put(sub.getLocation(), sub.getLastModified());
} }
lastFetched.put(sub.getLocation(), "" + sub.getLastFetched()); lastFetched.put(sub.getLocation(), Long.toString(sub.getLastFetched()));
} }
try { try {
ConfigParser.write(etags, this.etagsFile); ConfigParser.write(etags, this.etagsFile);
} catch (IOException exp) {}
try {
ConfigParser.write(lastModified, this.lastModifiedFile); ConfigParser.write(lastModified, this.lastModifiedFile);
} catch (IOException exp) {}
try {
ConfigParser.write(lastFetched, this.lastFetchedFile); ConfigParser.write(lastFetched, this.lastFetchedFile);
} catch (IOException exp) { } catch (IOException exp) {}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment