Package net.i2p.data
Class DataStructureImpl
- 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 DataStructureImpl extends Object implements DataStructure, Serializable
Base implementation of all data structures- Author:
- jrandom
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DataStructureImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HashcalculateHash()Calculate the SHA256 value of this object (useful for a few scenarios)voidfromBase64(String data)Load the structure from the base 64 encoded data provided Warning - many classes will throw IllegalStateException if data is already set.voidfromByteArray(byte[] data)Load the structure from the data provided Warning - many classes will throw IllegalStateException if data is already set.protected intread(InputStream in, byte[] target)Repeated reads until the buffer is full or IOException is thrownStringtoBase64()render the structure into modified base 64 notationbyte[]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
-
-
-
-
Method Detail
-
toBase64
public String toBase64()
Description copied from interface:DataStructurerender the structure into modified base 64 notation- Specified by:
toBase64in interfaceDataStructure- Returns:
- null on error
-
fromBase64
public void fromBase64(String data) throws DataFormatException
Description copied from interface:DataStructureLoad 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.- Specified by:
fromBase64in interfaceDataStructure- Throws:
DataFormatException
-
calculateHash
public Hash calculateHash()
Description copied from interface:DataStructureCalculate the SHA256 value of this object (useful for a few scenarios)- Specified by:
calculateHashin interfaceDataStructure- Returns:
- SHA256 hash, or null if there were problems (data format or io errors)
-
toByteArray
public byte[] toByteArray()
- Specified by:
toByteArrayin interfaceDataStructure- Returns:
- may be null if data is not set
-
fromByteArray
public void fromByteArray(byte[] data) throws DataFormatExceptionDescription copied from interface:DataStructureLoad 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.- Specified by:
fromByteArrayin interfaceDataStructure- Throws:
DataFormatException
-
read
protected int read(InputStream in, byte[] target) throws IOException
Repeated reads until the buffer is full or IOException is thrown- Returns:
- number of bytes read (should always equal target.length)
- Throws:
IOException
-
-