Changeset b3d1a76


Ignore:
Timestamp:
Dec 26, 2010 1:04:52 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cd0d062
Parents:
824d5a0
Message:

Prep for caching by making SimpleDataStructures? immutable after data has been set.

File:
1 edited

Legend:

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

    r824d5a0 rb3d1a76  
    2020 *
    2121 * Implemented in 0.8.2 and retrofitted over several of the classes in this package.
     22 *
     23 * As of 0.8.3, SDS objects may be cached. An SDS may be instantiated with null data,
     24 * and setData(null) is also OK. However,
     25 * once non-null data is set, the data reference is immutable;
     26 * subsequent attempts to set the data via setData(), readBytes(),
     27 * or fromBase64() will throw a RuntimeException.
    2228 *
    2329 * @since 0.8.2
     
    5864     * @param data of correct length, or null
    5965     * @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok)
     66     * @throws RuntimeException if data already set.
    6067     */
    6168    public void setData(byte[] data) {
     69        if (_data != null)
     70            throw new RuntimeException("Data already set");
    6271        if (data != null && data.length != _length)
    6372            throw new IllegalArgumentException("Bad data length");
     
    6574    }
    6675
     76    /**
     77     * Sets the data.
     78     * @param data of correct length, or null
     79     * @throws RuntimeException if data already set.
     80     */
    6781    public void readBytes(InputStream in) throws DataFormatException, IOException {
     82        if (_data != null)
     83            throw new RuntimeException("Data already set");
    6884        _data = new byte[_length];
    6985        int read = read(in, _data);
     
    86102     * Sets the data.
    87103     * @throws DataFormatException if decoded data is not the legal number of bytes or on decoding error
     104     * @throws RuntimeException if data already set.
    88105     */
    89106    @Override
     
    163180        return DataHelper.eq(_data, ((SimpleDataStructure) obj)._data);
    164181    }
    165    
    166182}
Note: See TracChangeset for help on using the changeset viewer.