use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.
the class RequestLeaseSetMessage method doWriteMessage.
@Override
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
if (_sessionId == null)
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
ByteArrayOutputStream os = new ByteArrayOutputStream(256);
try {
_sessionId.writeBytes(os);
DataHelper.writeLong(os, 1, _endpoints.size());
for (int i = 0; i < _endpoints.size(); i++) {
Hash router = getRouter(i);
router.writeBytes(os);
TunnelId tunnel = getTunnelId(i);
tunnel.writeBytes(os);
}
DataHelper.writeDate(os, _end);
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Error writing out the message data", dfe);
}
return os.toByteArray();
}
use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.
the class RequestVariableLeaseSetMessage method doReadMessage.
@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
try {
if (_sessionId != null)
throw new IllegalStateException();
_sessionId = new SessionId();
_sessionId.readBytes(in);
int numTunnels = (int) DataHelper.readLong(in, 1);
for (int i = 0; i < numTunnels; i++) {
Lease lease = new Lease();
lease.readBytes(in);
_endpoints.add(lease);
}
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Unable to load the message data", dfe);
}
}
use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.
the class RequestVariableLeaseSetMessage method doWriteMessage.
@Override
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
if (_sessionId == null)
throw new I2CPMessageException("No data");
ByteArrayOutputStream os = new ByteArrayOutputStream(256);
try {
_sessionId.writeBytes(os);
DataHelper.writeLong(os, 1, _endpoints.size());
for (int i = 0; i < _endpoints.size(); i++) {
_endpoints.get(i).writeBytes(os);
}
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Error writing out the message data", dfe);
}
return os.toByteArray();
}
use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.
the class SendMessageMessage method readMessage.
/**
* Read the body into the data structures
*
* @throws IOException
*/
@Override
public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOException {
if (type != getType())
throw new I2CPMessageException("Invalid message type (found: " + type + " supported: " + getType() + " class: " + getClass().getName() + ")");
if (length < 0)
throw new IOException("Negative payload size");
try {
_sessionId = new SessionId();
_sessionId.readBytes(in);
_destination = Destination.create(in);
_payload = new Payload();
_payload.readBytes(in);
_nonce = DataHelper.readLong(in, 4);
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Unable to load the message data", dfe);
}
}
use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.
the class SessionConfig method writeBytes.
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
if ((_destination == null) || (_options == null) || (_signature == null) || (_creationDate == null))
throw new DataFormatException("Not enough data to create the session config");
_destination.writeBytes(out);
// UTF-8
DataHelper.writeProperties(out, _options, true);
DataHelper.writeDate(out, _creationDate);
_signature.writeBytes(out);
}
Aggregations