java.lang.Object
net.i2p.data.DataStructureImpl
All Implemented Interfaces:
Serializable, DataStructure
Direct Known Subclasses:
AbuseReason, AbuseSeverity, Certificate, DatabaseEntry, DateAndFlags, DeliveryInstructions, GarlicClove, KeysAndCert, Lease, Payload, RouterAddress, SessionConfig

public abstract class DataStructureImplextends Object implements DataStructure, Serializable
Base implementation of all data structures.
See Also:
  • Constructor Details

    • DataStructureImpl

      public DataStructureImpl()
      Constructor for data structure implementations that serialize themselves to a stream.
  • Method Details

    • toBase64

      public String toBase64()
      Description copied from interface: DataStructure
      Render the structure into modified base 64 notation.
      Specified by:
      toBase64 in interface DataStructure
      Returns:
      null on error
    • fromBase64

      public void fromBase64(String data) throws DataFormatException
      Description copied from interface: DataStructure
      Load the structure from the provided base64 string.

      Warning - many classes will throw IllegalStateException if data is already set. Warning - many classes will throw IllegalArgumentException if data is the wrong size.

      Specified by:
      fromBase64 in interface DataStructure
      Parameters:
      data - base64 encoded string to load from
      Throws:
      DataFormatException - if the data format is invalid
    • calculateHash

      public Hash calculateHash()
      Description copied from interface: DataStructure
      Calculate the SHA256 value of this object (useful for a few scenarios).
      Specified by:
      calculateHash in interface DataStructure
      Returns:
      SHA256 hash, or null if there were problems (data format or io errors)
    • toByteArray

      public byte[] toByteArray()
      Description copied from interface: DataStructure
      Convert the structure to a byte array.
      Specified by:
      toByteArray in interface DataStructure
      Returns:
      may be null if data is not set
    • fromByteArray

      public void fromByteArray(byte[] data) throws DataFormatException
      Description copied from interface: DataStructure
      Loads 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.

      Specified by:
      fromByteArray in interface DataStructure
      Parameters:
      data - byte array to load from
      Throws:
      DataFormatException - if the data format is invalid
    • read

      protected int read(InputStream in, byte[] target) throws IOException
      Repeated reads until buffer is full or IOException is thrown.
      Parameters:
      in - input stream to read from
      target - byte array to read into
      Returns:
      number of bytes read (should always equal target.length)
      Throws:
      IOException - if an I/O error occurs