/** * Receive MSRP SEND request * * @param txId Transaction ID * @param headers Request headers * @param flag Continuation flag * @param data Received data * @param totalSize Total size of the content * @throws NetworkException * @throws PayloadException * @throws ContactManagerException */ public void receiveMsrpSend( String txId, Hashtable<String, String> headers, int flag, byte[] data, long totalSize) throws PayloadException, NetworkException, ContactManagerException { mIsEstablished = true; if (sLogger.isActivated()) { sLogger.debug( new StringBuilder("SEND request received (flag=") .append(flag) .append(", transaction=") .append(txId) .append(", totalSize=") .append(totalSize) .append(")") .toString()); } String msgId = headers.get(MsrpConstants.HEADER_MESSAGE_ID); boolean failureReportNeeded = true; String failureHeader = headers.get(MsrpConstants.HEADER_FAILURE_REPORT); if ((failureHeader != null) && failureHeader.equalsIgnoreCase("no")) { failureReportNeeded = false; } if (failureReportNeeded) { sendMsrpResponse(MsrpConstants.STATUS_200_OK, txId, headers); } if (data == null) { if (sLogger.isActivated()) { sLogger.debug("Empty chunk"); } return; } mReceivedChunks.addChunk(data); if (flag == MsrpConstants.FLAG_LAST_CHUNK) { if (sLogger.isActivated()) { sLogger.info("Transfer terminated"); } byte[] dataContent = mReceivedChunks.getReceivedData(); mReceivedChunks.resetCache(); String contentTypeHeader = headers.get(MsrpConstants.HEADER_CONTENT_TYPE); mMsrpEventListener.receiveMsrpData(msgId, dataContent, contentTypeHeader); boolean successReportNeeded = false; String reportHeader = headers.get(MsrpConstants.HEADER_SUCCESS_REPORT); if ((reportHeader != null) && reportHeader.equalsIgnoreCase("yes")) { successReportNeeded = true; } if (successReportNeeded) { sendMsrpReportRequest(txId, headers, dataContent.length, totalSize); } } else if (flag == MsrpConstants.FLAG_ABORT_CHUNK) { if (sLogger.isActivated()) { sLogger.info("Transfer aborted"); } mMsrpEventListener.msrpTransferAborted(); } else if (flag == MsrpConstants.FLAG_MORE_CHUNK) { if (sLogger.isActivated()) { sLogger.debug("Transfer in progress..."); } byte[] dataContent = mReceivedChunks.getReceivedData(); boolean resetCache = mMsrpEventListener.msrpTransferProgress( mReceivedChunks.getCurrentSize(), totalSize, dataContent); /* * Data are only consumed chunk by chunk in file transfer & image share. In a chat * session only the whole message is consumed after receiving the last chunk. */ if (resetCache) { mReceivedChunks.resetCache(); } } }