Package net.i2p.data

Interface DataStructure

All Known Implementing Classes:
AbuseReason, AbuseSeverity, Certificate, DatabaseEntry, DataStructureImpl, DateAndFlags, DeliveryInstructions, Destination, EncryptedBuildRecord, EncryptedLeaseSet, GarlicClove, Hash, Hash384, Hash512, InfoHash, KeyCertificate, KeysAndCert, Lease, Lease2, LeaseSet, LeaseSet2, LocalHash, MetaLease, MetaLeaseSet, NextSessionKey, NID, NodeInfo, Payload, Peer, PrivateKey, PublicKey, RouterAddress, RouterIdentity, RouterInfo, RSASigningPrivateCrtKey, SendMessageOptions, SessionConfig, SessionKey, SessionKeyAndNonce, SHA1Hash, ShortEncryptedBuildRecord, Signature, SigningPrivateKey, SigningPublicKey, SimpleDataStructure, TokenKey, VerifiedDestination

public interface DataStructure
Defines the class as a standard object with particular bit representation, exposing methods to read and write that representation.

Do not reuse objects. Many of modifying methods contain checks to prevent altering a DataStructure after it is initialized. This protects the netdb, messages that contain DataStructures, caches, and the object itself from simple causes of corruption, by throwing IllegalStateExceptions. These checks are not necessarily thread-safe, and are not guaranteed to catch all possible means of corruption. Beware of other avenues of corruption, such as directly modifying data stored in byte[] objects.

Author:
jrandom
  • Method Summary

    Modifier and Type
    Method
    Description
    Calculate the SHA256 value of this object (useful for a few scenarios)
    void
    Load the structure from the base 64 encoded data provided Warning - many classes will throw IllegalStateException if data is already set.
    void
    fromByteArray(byte[] data)
    Load the structure from the data provided Warning - many classes will throw IllegalStateException if data is already set.
    void
    Load up the current object with data from the given stream.
    render the structure into modified base 64 notation
    byte[]
     
    void
    Write out the data structure to the stream, using the format defined in the I2P data structure specification.
  • Method Details

    • readBytes

      void readBytes(InputStream in) throws DataFormatException, IOException
      Load up the current object with data from the given stream. Data loaded this way must match the I2P data structure specification. Warning - many classes will throw IllegalStateException if data is already set.
      Parameters:
      in - stream to read from
      Throws:
      DataFormatException - if the data is improperly formatted
      IOException - if there was a problem reading the stream
    • writeBytes

      void writeBytes(OutputStream out) throws DataFormatException, IOException
      Write out the data structure to the stream, using the format defined in the I2P data structure specification.
      Parameters:
      out - stream to write to
      Throws:
      DataFormatException - if the data was incomplete or not yet ready to be written
      IOException - if there was a problem writing to the stream
    • toBase64

      String toBase64()
      render the structure into modified base 64 notation
      Returns:
      null on error
    • fromBase64

      void fromBase64(String data) throws DataFormatException
      Load the structure from the base 64 encoded data provided Warning - many classes will throw IllegalStateException if data is already set. Warning - many classes will throw IllegalArgumentException if data is the wrong size.
      Throws:
      DataFormatException
    • toByteArray

      byte[] toByteArray()
      Returns:
      may be null if data is not set
    • fromByteArray

      void fromByteArray(byte[] data) throws DataFormatException
      Load the structure from the data provided Warning - many classes will throw IllegalStateException if data is already set. Warning - many classes will throw IllegalArgumentException if data is the wrong size.
      Throws:
      DataFormatException
    • calculateHash

      Hash calculateHash()
      Calculate the SHA256 value of this object (useful for a few scenarios)
      Returns:
      SHA256 hash, or null if there were problems (data format or io errors)