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
Base implementation of all data structures.
- See Also:
Constructor Summary
ConstructorsConstructorDescriptionConstructor for data structure implementations that serialize themselves to a stream.Method Summary
Public MethodsModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataStructure
readBytes, writeBytesModifier and TypeMethodDescriptionvoidreadBytes(InputStream in) Load up the current object with data from the given stream.voidwriteBytes(OutputStream out) Write out the data structure to the stream, using the format defined in the I2P data structure specification.
Constructor Details
DataStructureImpl
public DataStructureImpl()Constructor for data structure implementations that serialize themselves to a stream.
Method Details
toBase64
Description copied from interface:DataStructureRender the structure into modified base 64 notation.- Specified by:
toBase64in interfaceDataStructure- Returns:
- null on error
fromBase64
Description copied from interface:DataStructureLoad 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:
fromBase64in interfaceDataStructure- Parameters:
data- base64 encoded string to load from- Throws:
DataFormatException- if the data format is invalid
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()Description copied from interface:DataStructureConvert the structure to a byte array.- Specified by:
toByteArrayin interfaceDataStructure- Returns:
- may be null if data is not set
fromByteArray
Description copied from interface:DataStructureLoads structure from the data providedWarning - 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- Parameters:
data- byte array to load from- Throws:
DataFormatException- if the data format is invalid
read
Repeated reads until buffer is full or IOException is thrown.- Parameters:
in- input stream to read fromtarget- byte array to read into- Returns:
- number of bytes read (should always equal target.length)
- Throws:
IOException- if an I/O error occurs