Package net.i2p.data

Class SimpleDataStructure

java.lang.Object
net.i2p.data.SimpleDataStructure
All Implemented Interfaces:
DataStructure
Direct Known Subclasses:
EncryptedBuildRecord, Hash, Hash384, Hash512, NodeInfo, PrivateKey, PublicKey, SessionKey, SHA1Hash, Signature, SigningPrivateKey, SigningPublicKey

public abstract class SimpleDataStructure
extends Object
implements DataStructure
A SimpleDataStructure contains only a single fixed-length byte array. Implemented in 0.8.2 and retrofitted over several of the classes in this package. As of 0.8.3, SDS objects may be cached. An SDS may be instantiated with null data, and setData(null) is also OK. However, once non-null data is set, the data reference is immutable; subsequent attempts to set the data via setData(), readBytes(), fromByteArray(), or fromBase64() will throw a RuntimeException. As of 0.9.48, no longer extends DataStrucureImpl to save space
Since:
0.8.2
Author:
zzz
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected byte[] _data  
  • Constructor Summary

    Constructors 
    Constructor Description
    SimpleDataStructure()
    A new instance with the data set to null.
    SimpleDataStructure​(byte[] data)  
  • Method Summary

    Modifier and Type Method Description
    Hash calculateHash()
    Calculate the SHA256 value of this object (useful for a few scenarios)
    boolean equals​(Object obj)
    Warning - this returns true for two different classes with the same size and same data, e.g.
    void fromBase64​(String data)
    Sets the data.
    void fromByteArray​(byte[] data)
    Does the same thing as setData() but null not allowed.
    byte[] getData()
    Get the data reference (not a copy)
    int hashCode()
    We assume the data has enough randomness in it, so use the first 4 bytes for speed.
    abstract int length()
    The legal length of the byte array in this data structure
    protected int read​(InputStream in, byte[] target)
    Repeated reads until the buffer is full or IOException is thrown
    void readBytes​(InputStream in)
    Sets the data.
    void setData​(byte[] data)
    Sets the data.
    String toBase64()
    render the structure into modified base 64 notation
    byte[] toByteArray()  
    String toString()  
    void writeBytes​(OutputStream out)
    Write out the data structure to the stream, using the format defined in the I2P data structure specification.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait