Changeset e691245 for core/java


Ignore:
Timestamp:
Dec 2, 2018 3:21:30 PM (20 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ee722b7
Parents:
7c928f9
Message:

DataHelper?: Minor efficiency improvements in Properties methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    r7c928f9 re691245  
    149149    public static Properties readProperties(InputStream rawStream, Properties props)
    150150        throws DataFormatException, IOException {
    151         long size = readLong(rawStream, 2);
    152         byte data[] = new byte[(int) size];
    153         int read = read(rawStream, data);
    154         if (read != size) throw new DataFormatException("Not enough data to read the properties, expected " + size + " but got " + read);
     151        int size = (int) readLong(rawStream, 2);
     152        if (size == 0)
     153            return props;
     154        byte data[] = new byte[size];
     155        // full read guaranteed
     156        read(rawStream, data);
    155157        ByteArrayInputStream in = new ByteArrayInputStream(data);
    156158        while (in.available() > 0) {
     
    214216    public static void writeProperties(OutputStream rawStream, Properties props, boolean utf8)
    215217            throws DataFormatException, IOException {
    216         writeProperties(rawStream, props, utf8, props != null && !(props instanceof OrderedProperties));
     218        writeProperties(rawStream, props, utf8, props != null && props.size() > 1 && !(props instanceof OrderedProperties));
    217219    }
    218220
     
    243245        if (props != null && !props.isEmpty()) {
    244246            Properties p;
    245             if (sort) {
     247            if (sort && props.size() > 1) {
    246248                p = new OrderedProperties();
    247249                p.putAll(props);
     
    867869        size &= 0xff;
    868870        byte raw[] = new byte[size];
    869         int read = read(in, raw);
    870         // was DataFormatException
    871         if (read != size) throw new EOFException("EOF reading string");
     871        // full read guaranteed
     872        read(in, raw);
    872873        // the following constructor throws an UnsupportedEncodingException which is an IOException,
    873874        // but that's only if UTF-8 is not supported. Other encoding errors are not thrown.
Note: See TracChangeset for help on using the changeset viewer.