DataHelper: Minor efficiency improvements in Properties methods

This commit is contained in:
zzz
2018-12-02 15:21:30 +00:00
parent 7c928f99ea
commit e6912453e0
3 changed files with 22 additions and 10 deletions

View File

@ -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");

View File

@ -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)

View File

@ -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 = "";