/**
* @see MsnMimeMessage#toOutgoingMsg(MsnProtocol)
*/
@Override
public OutgoingMSG[] toOutgoingMsg(MsnProtocol protocol) {
OutgoingMSG message = new OutgoingMSG(protocol)//;
{
protected void receivedResponse(MsnSession session, MsnIncomingMessage response)
{
MsnP2PMessage.this.receivedResponse(session, response);
}
};
message.setMsgType(OutgoingMSG.TYPE_MSNC1);
byte[] mimeMessageHeader = Charset.encodeAsByteArray(toString());
byte[] body = bodyToMessage();
if (body == null) {
body = new byte[0];
}
// move to next data, as the body is the whole actual body
// and we obey the length,currentLength and offset
// if body is not the whole (length not equal to total length )
// it means that external will take care fill the data
if(getTotalLength() > getCurrentLength() && body.length == getTotalLength())
{
byte[] newBody = new byte[getCurrentLength()];
System.arraycopy(body, (int)getOffset(), newBody, 0, newBody.length);
body = newBody;
}
ByteBuffer msg = ByteBuffer
.allocate(mimeMessageHeader.length + BINARY_HEADER_LEN
+ body.length + BINARY_FOOTER_LEN);
msg.put(mimeMessageHeader);
msg.put(binaryHeader);
msg.put(body);
msg.put(binaryFooter);
message.setMsg(msg.array());
return new OutgoingMSG[] { message };
}