Package net.i2p.data.i2cp
Class I2CPMessageImpl
- java.lang.Object
-
- net.i2p.data.DataStructureImpl
-
- net.i2p.data.i2cp.I2CPMessageImpl
-
- All Implemented Interfaces:
Serializable,DataStructure,I2CPMessage
- Direct Known Subclasses:
BandwidthLimitsMessage,BlindingInfoMessage,CreateLeaseSetMessage,CreateSessionMessage,DestLookupMessage,DestReplyMessage,DestroySessionMessage,DisconnectMessage,GetBandwidthLimitsMessage,GetDateMessage,HostLookupMessage,HostReplyMessage,MessagePayloadMessage,MessageStatusMessage,PoisonI2CPMessage,ReceiveMessageBeginMessage,ReceiveMessageEndMessage,ReconfigureSessionMessage,ReportAbuseMessage,RequestLeaseSetMessage,RequestVariableLeaseSetMessage,SendMessageMessage,SessionStatusMessage,SetDateMessage
public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPMessage
Defines the base message implementation.- Author:
- jrandom
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description I2CPMessageImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voiddoReadMessage(InputStream buf, int size)Read in the payload part of the message (after the initial 4 byte size and 1 byte type)protected abstract byte[]doWriteMessage()Write out the payload part of the message (not including the 4 byte size and 1 byte type)voidreadBytes(InputStream in)Load up the current object with data from the given stream.voidreadMessage(InputStream in)Validate the type and size of the message, and then read the message into the data structures.voidreadMessage(InputStream in, int length, int type)Read the body into the data structuresSessionIdsessionId()Return the SessionId for this type of message.voidwriteBytes(OutputStream out)Write out the data structure to the stream, using the format defined in the I2P data structure specification.voidwriteMessage(OutputStream out)Write out the full message to the stream, including the 4 byte size and 1 byte type header.-
Methods inherited from class net.i2p.data.DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, 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
calculateHash, fromBase64, fromByteArray, toBase64, toByteArray
-
Methods inherited from interface net.i2p.data.i2cp.I2CPMessage
getType
-
-
-
-
Method Detail
-
readMessage
public void readMessage(InputStream in) throws I2CPMessageException, IOException
Validate the type and size of the message, and then read the message into the data structures.- Specified by:
readMessagein interfaceI2CPMessage- Parameters:
in- stream to read from- Throws:
IOExceptionI2CPMessageException- if the stream doesn't contain a valid message that this class can read.
-
readMessage
public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOException
Read the body into the data structures- Specified by:
readMessagein interfaceI2CPMessage- Parameters:
length- number of bytes in the message payloadin- stream to read fromtype- type of message (should equal getType())- Throws:
IOExceptionI2CPMessageException- if the stream doesn't contain a valid message that this class can read.
-
doReadMessage
protected abstract void doReadMessage(InputStream buf, int size) throws I2CPMessageException, IOException
Read in the payload part of the message (after the initial 4 byte size and 1 byte type)- Parameters:
buf- InputStreamsize- payload size- Throws:
I2CPMessageExceptionIOException
-
doWriteMessage
protected abstract byte[] doWriteMessage() throws I2CPMessageException, IOExceptionWrite out the payload part of the message (not including the 4 byte size and 1 byte type)- Returns:
- byte array
- Throws:
I2CPMessageExceptionIOException
-
writeMessage
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException
Write out the full message to the stream, including the 4 byte size and 1 byte type header.- Specified by:
writeMessagein interfaceI2CPMessage- Parameters:
out- OutputStream- Throws:
IOExceptionI2CPMessageException- if the current object doesn't have sufficient data to write a properly formatted message.
-
readBytes
public void readBytes(InputStream in) throws DataFormatException, IOException
Description copied from interface:DataStructureLoad 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.- Specified by:
readBytesin interfaceDataStructure- Parameters:
in- stream to read from- Throws:
DataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
-
writeBytes
public void writeBytes(OutputStream out) throws DataFormatException, IOException
Description copied from interface:DataStructureWrite out the data structure to the stream, using the format defined in the I2P data structure specification.- Specified by:
writeBytesin interfaceDataStructure- Parameters:
out- stream to write to- Throws:
DataFormatException- if the data was incomplete or not yet ready to be writtenIOException- if there was a problem writing to the stream
-
sessionId
public SessionId sessionId()
Return the SessionId for this type of message. Most but not all message types include a SessionId. The ones that do already define getSessionId(), but some return a SessionId and some return a long, so we define a new method here.- Specified by:
sessionIdin interfaceI2CPMessage- Returns:
- null always. Extending classes with a SessionId must override.
- Since:
- 0.9.21
-
-