Smack

org.jivesoftware.smackx.filetransfer
Class OutgoingFileTransfer

java.lang.Object
  extended byorg.jivesoftware.smackx.filetransfer.FileTransfer
      extended byorg.jivesoftware.smackx.filetransfer.OutgoingFileTransfer

public class OutgoingFileTransfer
extends FileTransfer

Handles the sending of a file to another user. File transfer's in jabber have several steps and there are several methods in this class that handle these steps differently.

Author:
Alexander Wenckus

Nested Class Summary
static class OutgoingFileTransfer.NegotiationProgress
          A callback class to retrive the status of an outgoing transfer negotiation process.
 
Nested classes inherited from class org.jivesoftware.smackx.filetransfer.FileTransfer
FileTransfer.Error, FileTransfer.Status
 
Field Summary
 
Fields inherited from class org.jivesoftware.smackx.filetransfer.FileTransfer
amountWritten, negotiator, streamID
 
Constructor Summary
protected OutgoingFileTransfer(String initiator, String target, String streamID, FileTransferNegotiator transferNegotiator)
           
 
Method Summary
 void cancel()
          Cancels the file transfer.
 long getBytesSent()
          Returns the amount of bytes that have been sent for the file transfer.
protected  OutputStream getOutputStream()
          Returns the output stream connected to the peer to transfer the file.
static int getResponseTimeout()
          Returns the time in milliseconds after which the file transfer negotiation process will timeout if the other user has not responded.
 void sendFile(File file, String description)
          This method handles the stream negotiation process and transmits the file to the remote user.
 OutputStream sendFile(String fileName, long fileSize, String description)
          This method handles the negotiation of the file transfer and the stream, it only returns the created stream after the negotiation has been completed.
 void sendFile(String fileName, long fileSize, String description, OutgoingFileTransfer.NegotiationProgress progress)
          This methods handles the transfer and stream negotiation process.
protected  void setOutputStream(OutputStream stream)
           
static void setResponseTimeout(int responseTimeout)
          Sets the time in milliseconds after which the file transfer negotiation process will timeout if the other user has not responded.
 
Methods inherited from class org.jivesoftware.smackx.filetransfer.FileTransfer
getAmountWritten, getError, getException, getFileName, getFilePath, getFileSize, getPeer, getProgress, getStatus, isDone, setError, setException, setFileInfo, setFileInfo, setStatus, updateStatus, writeToStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutgoingFileTransfer

protected OutgoingFileTransfer(String initiator,
                               String target,
                               String streamID,
                               FileTransferNegotiator transferNegotiator)
Method Detail

getResponseTimeout

public static int getResponseTimeout()
Returns the time in milliseconds after which the file transfer negotiation process will timeout if the other user has not responded.

Returns:
Returns the time in milliseconds after which the file transfer negotiation process will timeout if the remote user has not responded.

setResponseTimeout

public static void setResponseTimeout(int responseTimeout)
Sets the time in milliseconds after which the file transfer negotiation process will timeout if the other user has not responded.

Parameters:
responseTimeout - The timeout time in milliseconds.

setOutputStream

protected void setOutputStream(OutputStream stream)

getOutputStream

protected OutputStream getOutputStream()
Returns the output stream connected to the peer to transfer the file. It is only available after it has been succesfully negotiated by the StreamNegotiator.

Returns:
Returns the output stream connected to the peer to transfer the file.

sendFile

public OutputStream sendFile(String fileName,
                             long fileSize,
                             String description)
                      throws XMPPException
This method handles the negotiation of the file transfer and the stream, it only returns the created stream after the negotiation has been completed.

Parameters:
fileName - The name of the file that will be transmitted. It is preferable for this name to have an extension as it will be used to determine the type of file it is.
fileSize - The size in bytes of the file that will be transmitted.
description - A description of the file that will be transmitted.
Returns:
The OutputStream that is connected to the peer to transmit the file.
Throws:
XMPPException - Thrown if an error occurs during the file transfer negotiation process.

sendFile

public void sendFile(String fileName,
                     long fileSize,
                     String description,
                     OutgoingFileTransfer.NegotiationProgress progress)
This methods handles the transfer and stream negotiation process. It returns immediately and its progress can be monitored through the OutgoingFileTransfer.NegotiationProgress callback. When the negotiation process is complete the OutputStream can be retrieved from the callback via the OutgoingFileTransfer.NegotiationProgress.getOutputStream() method.

Parameters:
fileName - The name of the file that will be transmitted. It is preferable for this name to have an extension as it will be used to determine the type of file it is.
fileSize - The size in bytes of the file that will be transmitted.
description - A description of the file that will be transmitted.
progress - A callback to monitor the progress of the file transfer negotiation process and to retrieve the OutputStream when it is complete.

sendFile

public void sendFile(File file,
                     String description)
              throws XMPPException
This method handles the stream negotiation process and transmits the file to the remote user. It returns immediatly and the progress of the file transfer can be monitored through several methods:

Throws:
XMPPException - If there is an error during the negotiation process or the sending of the file.

getBytesSent

public long getBytesSent()
Returns the amount of bytes that have been sent for the file transfer. Or -1 if the file transfer has not started.

Note: This method is only useful when the sendFile(File, String) method is called, as it is the only method that actualy transmits the file.

Returns:
Returns the amount of bytes that have been sent for the file transfer. Or -1 if the file transfer has not started.

cancel

public void cancel()
Description copied from class: FileTransfer
Cancels the file transfer.

Specified by:
cancel in class FileTransfer

Smack

Copyright © 2003 Jive Software.