From e6912453e080aec6b467eb531a80c0dc45c004bb Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 2 Dec 2018 15:21:30 +0000 Subject: [PATCH] DataHelper: Minor efficiency improvements in Properties methods --- core/java/src/net/i2p/data/DataHelper.java | 19 ++++++++++--------- history.txt | 11 +++++++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 6e98805f59..c393cbf4c1 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -148,10 +148,12 @@ public class DataHelper { */ public static Properties readProperties(InputStream rawStream, Properties props) throws DataFormatException, IOException { - long size = readLong(rawStream, 2); - byte data[] = new byte[(int) size]; - int read = read(rawStream, data); - if (read != size) throw new DataFormatException("Not enough data to read the properties, expected " + size + " but got " + read); + int size = (int) readLong(rawStream, 2); + if (size == 0) + return props; + byte data[] = new byte[size]; + // full read guaranteed + read(rawStream, data); ByteArrayInputStream in = new ByteArrayInputStream(data); while (in.available() > 0) { String key = readString(in); @@ -213,7 +215,7 @@ public class DataHelper { */ public static void writeProperties(OutputStream rawStream, Properties props, boolean utf8) throws DataFormatException, IOException { - writeProperties(rawStream, props, utf8, props != null && !(props instanceof OrderedProperties)); + writeProperties(rawStream, props, utf8, props != null && props.size() > 1 && !(props instanceof OrderedProperties)); } /** @@ -242,7 +244,7 @@ public class DataHelper { throws DataFormatException, IOException { if (props != null && !props.isEmpty()) { Properties p; - if (sort) { + if (sort && props.size() > 1) { p = new OrderedProperties(); p.putAll(props); } else { @@ -866,9 +868,8 @@ public class DataHelper { return ""; // reduce object proliferation size &= 0xff; byte raw[] = new byte[size]; - int read = read(in, raw); - // was DataFormatException - if (read != size) throw new EOFException("EOF reading string"); + // full read guaranteed + read(in, raw); // the following constructor throws an UnsupportedEncodingException which is an IOException, // but that's only if UTF-8 is not supported. Other encoding errors are not thrown. return new String(raw, "UTF-8"); diff --git a/history.txt b/history.txt index 8f10395929..3e65855c5b 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,14 @@ +2018-12-01 zzz + * I2CP: Add preliminary support for LS2 (proposal #123) + * Router: More support for LS2 types (proposal #123) + +2018-11-30 zzz + * Crypto: Move X25519 primitives from router to core (proposal #144) + * Data: Update LS2 sign/verify to match spec changes (proposal #123) + +2018-11-25 zzz + * Utils: Catch ProviderException in SelfSignedGenerator (ticket #2344) + 2018-11-20 zzz * GeoIP: Add support for Maxmind GeoLite2 format (ticket #2268) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index c10128fe62..fecba78d69 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 6; + public final static long BUILD = 7; /** for example "-test" */ public final static String EXTRA = "";