/** * */ package org.jivesoftware.smackx.filetransfer; import org.jivesoftware.smack.XMPPException; import java.io.*; /** * An incoming file transfer is created when the * {@link FileTransferManager#createIncomingFileTransfer(FileTransferRequest)} * method is invoked. It is a file being sent to the local user from another * user on the jabber network. There are two stages of the file transfer to be * concerned with and they can be handled in different ways depending upon the * method that is invoked on this class. *
* The first way that a file is recieved is by calling the * {@link #recieveFile()} method. This method, negotiates the appropriate stream * method and then returns the InputStream to read the file * data from. * * The second way that a file can be recieved through this class is by invoking * the {@link #recieveFile(File)} method. This method returns immediatly and * takes as its parameter a file on the local file system where the file * recieved from the transfer will be put. * * @author Alexander Wenckus */ public class IncomingFileTransfer extends FileTransfer { private FileTransferRequest recieveRequest; private Thread transferThread; private InputStream inputStream; protected IncomingFileTransfer(FileTransferRequest request, FileTransferNegotiator transferNegotiator) { super(request.getRequestor(), request.getStreamID(), transferNegotiator); this.recieveRequest = request; } /** * Negotiates the stream method to transfer the file over and then returns * the negotiated stream. * * @return The negotiated InputStream from which to read the data. * @throws XMPPException If there is an error in the negotiation process an exception * is thrown. */ public InputStream recieveFile() throws XMPPException { if (inputStream != null) { throw new IllegalStateException("Transfer already negotiated!"); } try { inputStream = negotiateStream(); } catch (XMPPException e) { setException(e); throw e; } return inputStream; } /** * This method negotitates the stream and then transfer's the file over the * negotiated stream. The transfered file will be saved at the provided * location. * * This method will return immedialtly, file transfer progress can be * monitored through several methods: * *