net.i2p.data
Class DataStructureImpl

java.lang.Object
  extended by net.i2p.data.DataStructureImpl
All Implemented Interfaces:
DataStructure
Direct Known Subclasses:
AbuseReason, AbuseSeverity, Address, Certificate, DeliveryInstructions, Destination, GarlicClove, Hash, I2CPMessageImpl, I2NPMessageImpl, Lease, LeaseSet, LeaseSetKeys, MessageId, Payload, PrivateKey, PublicKey, RouterAddress, RouterIdentity, RouterInfo, SessionConfig, SessionId, SessionKey, Signature, SigningPrivateKey, SigningPublicKey, TunnelId

public abstract class DataStructureImpl
extends java.lang.Object
implements DataStructure

Base implementation of all data structures

Author:
jrandom

Constructor Summary
DataStructureImpl()
           
 
Method Summary
 Hash calculateHash()
          Calculate the SHA256 value of this object (useful for a few scenarios)
 void fromBase64(java.lang.String data)
          Load the structure from the base 64 encoded data provided
 void fromByteArray(byte[] data)
           
protected  int read(java.io.InputStream in, byte[] target)
          Repeated reads until the buffer is full or IOException is thrown
 java.lang.String toBase64()
          render the structure into modified base 64 notation
 byte[] toByteArray()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.i2p.data.DataStructure
readBytes, writeBytes
 

Constructor Detail

DataStructureImpl

public DataStructureImpl()
Method Detail

toBase64

public java.lang.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(java.lang.String data)
                throws DataFormatException
Description copied from interface: DataStructure
Load the structure from the base 64 encoded data provided

Specified by:
fromBase64 in interface DataStructure
Throws:
DataFormatException

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()
Specified by:
toByteArray in interface DataStructure

fromByteArray

public void fromByteArray(byte[] data)
                   throws DataFormatException
Specified by:
fromByteArray in interface DataStructure
Throws:
DataFormatException

read

protected int read(java.io.InputStream in,
                   byte[] target)
            throws java.io.IOException
Repeated reads until the buffer is full or IOException is thrown

Returns:
number of bytes read (should always equal target.length)
Throws:
java.io.IOException