private OutputStream negotiateStream(String fileName, long fileSize,
String description) throws XMPPException {
// Negotiate the file transfer profile
if (!updateStatus(Status.initial, Status.negotiating_transfer)) {
throw new XMPPException("Illegal state change");
}
StreamNegotiator streamNegotiator = negotiator.negotiateOutgoingTransfer(
getPeer(), streamID, fileName, fileSize, description,
RESPONSE_TIMEOUT);
if (streamNegotiator == null) {
setStatus(Status.error);
setError(Error.no_response);
return null;
}
// Negotiate the stream
if (!updateStatus(Status.negotiating_transfer, Status.negotiating_stream)) {
throw new XMPPException("Illegal state change");
}
outputStream = streamNegotiator.createOutgoingStream(streamID,
initiator, getPeer());
if (!updateStatus(Status.negotiating_stream, Status.negotiated)) {
throw new XMPPException("Illegal state change");
}
return outputStream;
}