forked from I2P_Developers/i2p.i2p
DataHelper: Minor efficiency improvements in Properties methods
This commit is contained in:
@@ -148,10 +148,12 @@ public class DataHelper {
|
|||||||
*/
|
*/
|
||||||
public static Properties readProperties(InputStream rawStream, Properties props)
|
public static Properties readProperties(InputStream rawStream, Properties props)
|
||||||
throws DataFormatException, IOException {
|
throws DataFormatException, IOException {
|
||||||
long size = readLong(rawStream, 2);
|
int size = (int) readLong(rawStream, 2);
|
||||||
byte data[] = new byte[(int) size];
|
if (size == 0)
|
||||||
int read = read(rawStream, data);
|
return props;
|
||||||
if (read != size) throw new DataFormatException("Not enough data to read the properties, expected " + size + " but got " + read);
|
byte data[] = new byte[size];
|
||||||
|
// full read guaranteed
|
||||||
|
read(rawStream, data);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(data);
|
ByteArrayInputStream in = new ByteArrayInputStream(data);
|
||||||
while (in.available() > 0) {
|
while (in.available() > 0) {
|
||||||
String key = readString(in);
|
String key = readString(in);
|
||||||
@@ -213,7 +215,7 @@ public class DataHelper {
|
|||||||
*/
|
*/
|
||||||
public static void writeProperties(OutputStream rawStream, Properties props, boolean utf8)
|
public static void writeProperties(OutputStream rawStream, Properties props, boolean utf8)
|
||||||
throws DataFormatException, IOException {
|
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 {
|
throws DataFormatException, IOException {
|
||||||
if (props != null && !props.isEmpty()) {
|
if (props != null && !props.isEmpty()) {
|
||||||
Properties p;
|
Properties p;
|
||||||
if (sort) {
|
if (sort && props.size() > 1) {
|
||||||
p = new OrderedProperties();
|
p = new OrderedProperties();
|
||||||
p.putAll(props);
|
p.putAll(props);
|
||||||
} else {
|
} else {
|
||||||
@@ -866,9 +868,8 @@ public class DataHelper {
|
|||||||
return ""; // reduce object proliferation
|
return ""; // reduce object proliferation
|
||||||
size &= 0xff;
|
size &= 0xff;
|
||||||
byte raw[] = new byte[size];
|
byte raw[] = new byte[size];
|
||||||
int read = read(in, raw);
|
// full read guaranteed
|
||||||
// was DataFormatException
|
read(in, raw);
|
||||||
if (read != size) throw new EOFException("EOF reading string");
|
|
||||||
// the following constructor throws an UnsupportedEncodingException which is an IOException,
|
// 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.
|
// but that's only if UTF-8 is not supported. Other encoding errors are not thrown.
|
||||||
return new String(raw, "UTF-8");
|
return new String(raw, "UTF-8");
|
||||||
|
11
history.txt
11
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
|
2018-11-20 zzz
|
||||||
* GeoIP: Add support for Maxmind GeoLite2 format (ticket #2268)
|
* GeoIP: Add support for Maxmind GeoLite2 format (ticket #2268)
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 6;
|
public final static long BUILD = 7;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "";
|
||||||
|
Reference in New Issue
Block a user