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");
    }
    if (streamID == null) Log.e("myOutgoingFileTransfer", "null STREAMID");
    if (initiator == null) Log.e("myOutgoingFileTransfer", "null INITIATOR");
    if (getPeer() == null) Log.e("myOutgoingFileTransfer", "null GETPEER");
    outputStream = streamNegotiator.createOutgoingStream(streamID, initiator, getPeer());

    if (!updateStatus(Status.negotiating_stream, Status.negotiated)) {
      throw new XMPPException("Illegal state change");
    }
    return outputStream;
  }
 public PacketFilter getInitiationPacketFilter(String from, String streamID) {
   if (primaryFilter == null || secondaryFilter == null) {
     primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
     secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
   }
   return new OrFilter(primaryFilter, secondaryFilter);
 }
 public InputStream call() throws Exception {
   Packet streamInitiation =
       collector.nextResult(SmackConfiguration.getPacketReplyTimeout() * 2);
   if (streamInitiation == null) {
     throw new XMPPException("No response from remote client");
   }
   StreamNegotiator negotiator = determineNegotiator(streamInitiation);
   return negotiator.negotiateIncomingStream(streamInitiation);
 }
  public String[] getNamespaces() {
    String[] primary = primaryNegotiator.getNamespaces();
    String[] secondary = secondaryNegotiator.getNamespaces();

    String[] namespaces = new String[primary.length + secondary.length];
    System.arraycopy(primary, 0, namespaces, 0, primary.length);
    System.arraycopy(secondary, 0, namespaces, primary.length, secondary.length);

    return namespaces;
  }
  public OutputStream createOutgoingStream(String streamID, String initiator, String target)
      throws XMPPException {
    OutputStream stream;
    try {
      stream = primaryNegotiator.createOutgoingStream(streamID, initiator, target);
    } catch (XMPPException ex) {
      stream = secondaryNegotiator.createOutgoingStream(streamID, initiator, target);
    }

    return stream;
  }
 private void cleanup(final Connection connection) {
   if (transferObject.remove(connection) != null) {
     inbandTransferManager.cleanup();
   }
 }