FileTransferRequest.java

  1. /**
  2.  *
  3.  * Copyright 2003-2006 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.filetransfer;

  18. import org.jivesoftware.smack.SmackException.NotConnectedException;
  19. import org.jivesoftware.smackx.si.packet.StreamInitiation;
  20. import org.jxmpp.jid.Jid;

  21. /**
  22.  * A request to send a file recieved from another user.
  23.  *
  24.  * @author Alexander Wenckus
  25.  *
  26.  */
  27. public class FileTransferRequest {
  28.     private final StreamInitiation streamInitiation;

  29.     private final FileTransferManager manager;

  30.     /**
  31.      * A recieve request is constructed from the Stream Initiation request
  32.      * received from the initator.
  33.      *
  34.      * @param manager
  35.      *            The manager handling this file transfer
  36.      *
  37.      * @param si
  38.      *            The Stream initiaton recieved from the initiator.
  39.      */
  40.     public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
  41.         this.streamInitiation = si;
  42.         this.manager = manager;
  43.     }

  44.     /**
  45.      * Returns the name of the file.
  46.      *
  47.      * @return Returns the name of the file.
  48.      */
  49.     public String getFileName() {
  50.         return streamInitiation.getFile().getName();
  51.     }

  52.     /**
  53.      * Returns the size in bytes of the file.
  54.      *
  55.      * @return Returns the size in bytes of the file.
  56.      */
  57.     public long getFileSize() {
  58.         return streamInitiation.getFile().getSize();
  59.     }

  60.     /**
  61.      * Returns the description of the file provided by the requestor.
  62.      *
  63.      * @return Returns the description of the file provided by the requestor.
  64.      */
  65.     public String getDescription() {
  66.         return streamInitiation.getFile().getDesc();
  67.     }

  68.     /**
  69.      * Returns the mime-type of the file.
  70.      *
  71.      * @return Returns the mime-type of the file.
  72.      */
  73.     public String getMimeType() {
  74.         return streamInitiation.getMimeType();
  75.     }

  76.     /**
  77.      * Returns the fully-qualified jabber ID of the user that requested this
  78.      * file transfer.
  79.      *
  80.      * @return Returns the fully-qualified jabber ID of the user that requested
  81.      *         this file transfer.
  82.      */
  83.     public Jid getRequestor() {
  84.         return streamInitiation.getFrom();
  85.     }

  86.     /**
  87.      * Returns the stream ID that uniquely identifies this file transfer.
  88.      *
  89.      * @return Returns the stream ID that uniquely identifies this file
  90.      *         transfer.
  91.      */
  92.     public String getStreamID() {
  93.         return streamInitiation.getSessionID();
  94.     }

  95.     /**
  96.      * Returns the stream initiation packet that was sent by the requestor which
  97.      * contains the parameters of the file transfer being transfer and also the
  98.      * methods available to transfer the file.
  99.      *
  100.      * @return Returns the stream initiation packet that was sent by the
  101.      *         requestor which contains the parameters of the file transfer
  102.      *         being transfer and also the methods available to transfer the
  103.      *         file.
  104.      */
  105.     protected StreamInitiation getStreamInitiation() {
  106.         return streamInitiation;
  107.     }

  108.     /**
  109.      * Accepts this file transfer and creates the incoming file transfer.
  110.      *
  111.      * @return Returns the <b><i>IncomingFileTransfer</b></i> on which the
  112.      *         file transfer can be carried out.
  113.      */
  114.     public IncomingFileTransfer accept() {
  115.         return manager.createIncomingFileTransfer(this);
  116.     }

  117.     /**
  118.      * Rejects the file transfer request.
  119.      * @throws NotConnectedException
  120.      * @throws InterruptedException
  121.      */
  122.     public void reject() throws NotConnectedException, InterruptedException {
  123.         manager.rejectIncomingFileTransfer(this);
  124.     }

  125. }