Class OutgoingFileTransfer
- java.lang.Object
-
- org.jivesoftware.smackx.filetransfer.FileTransfer
-
- org.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceOutgoingFileTransfer.NegotiationProgressA callback class to retrieve the status of an outgoing transfer negotiation process.-
Nested classes/interfaces 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
Constructors Modifier Constructor Description protectedOutgoingFileTransfer(Jid initiator, Jid target, java.lang.String streamID, FileTransferNegotiator transferNegotiator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels the file transfer.longgetBytesSent()Returns the amount of bytes that have been sent for the file transfer.protected java.io.OutputStreamgetOutputStream()Returns the output stream connected to the peer to transfer the file.static intgetResponseTimeout()Returns the time in milliseconds after which the file transfer negotiation process will timeout if the other user has not responded.voidsendFile(java.io.File file, java.lang.String description)This method handles the stream negotiation process and transmits the file to the remote user.java.io.OutputStreamsendFile(java.lang.String fileName, long fileSize, java.lang.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.voidsendFile(java.lang.String fileName, long fileSize, java.lang.String description, OutgoingFileTransfer.NegotiationProgress progress)This methods handles the transfer and stream negotiation process.voidsendStream(java.io.InputStream in, java.lang.String fileName, long fileSize, java.lang.String description)This method handles the stream negotiation process and transmits the file to the remote user.voidsetCallback(OutgoingFileTransfer.NegotiationProgress negotiationProcess)protected voidsetException(java.lang.Exception exception)protected voidsetOutputStream(java.io.OutputStream stream)static voidsetResponseTimeout(int responseTimeout)Sets the time in milliseconds after which the file transfer negotiation process will timeout if the other user has not responded.protected voidsetStatus(FileTransfer.Status status)protected booleanupdateStatus(FileTransfer.Status oldStatus, FileTransfer.Status newStatus)-
Methods inherited from class org.jivesoftware.smackx.filetransfer.FileTransfer
getAmountWritten, getError, getException, getFileName, getFilePath, getFileSize, getPeer, getProgress, getStatus, getStreamID, isDone, setError, setFileInfo, setFileInfo, writeToStream
-
-
-
-
Constructor Detail
-
OutgoingFileTransfer
protected OutgoingFileTransfer(Jid initiator, Jid target, java.lang.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- TODO javadoc me please The timeout time in milliseconds.
-
setOutputStream
protected void setOutputStream(java.io.OutputStream stream)
-
getOutputStream
protected java.io.OutputStream getOutputStream()
Returns the output stream connected to the peer to transfer the file. It is only available after it has been successfully negotiated by theStreamNegotiator.- Returns:
- Returns the output stream connected to the peer to transfer the file.
-
sendFile
public java.io.OutputStream sendFile(java.lang.String fileName, long fileSize, java.lang.String description) throws XMPPException, SmackException, java.lang.InterruptedException
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- TODO javadoc me please 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- TODO javadoc me please The size in bytes of the file that will be transmitted.description- TODO javadoc me please A description of the file that will be transmitted.- Returns:
- The OutputStream that is connected to the peer to transmit the file.
- Throws:
XMPPException- if an XMPP protocol error was received. Thrown if an error occurs during the file transfer negotiation process.SmackException- if there was no response from the server.java.lang.InterruptedException- if the calling thread was interrupted.
-
sendFile
public void sendFile(java.lang.String fileName, long fileSize, java.lang.String description, OutgoingFileTransfer.NegotiationProgress progress)
This methods handles the transfer and stream negotiation process. It returns immediately and its progress will be updated through theOutgoingFileTransfer.NegotiationProgresscallback.- Parameters:
fileName- TODO javadoc me please 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- TODO javadoc me please The size in bytes of the file that will be transmitted.description- TODO javadoc me please A description of the file that will be transmitted.progress- TODO javadoc me please 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(java.io.File file, java.lang.String description) throws SmackException
This method handles the stream negotiation process and transmits the file to the remote user. It returns immediately and the progress of the file transfer can be monitored through several methods:- Parameters:
file- the file to transfer to the remote entity.description- a description for the file to transfer.- Throws:
SmackException- if Smack detected an exceptional situation. If there is an error during the negotiation process or the sending of the file.
-
sendStream
public void sendStream(java.io.InputStream in, java.lang.String fileName, long fileSize, java.lang.String description)
This method handles the stream negotiation process and transmits the file to the remote user. It returns immediately and the progress of the file transfer can be monitored through several methods:- Parameters:
in- the stream to transfer to the remote entity.fileName- the name of the file that is transferredfileSize- the size of the file that is transferreddescription- a description for the file to transfer.
-
setCallback
public void setCallback(OutgoingFileTransfer.NegotiationProgress negotiationProcess)
-
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 actually 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:FileTransferCancels the file transfer.- Specified by:
cancelin classFileTransfer
-
updateStatus
protected boolean updateStatus(FileTransfer.Status oldStatus, FileTransfer.Status newStatus)
- Overrides:
updateStatusin classFileTransfer
-
setStatus
protected void setStatus(FileTransfer.Status status)
- Overrides:
setStatusin classFileTransfer
-
setException
protected void setException(java.lang.Exception exception)
- Overrides:
setExceptionin classFileTransfer
-
-