mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
File transfer upgrade, 1.5 and beautification.
Fixed fault tolerant negotiator. SMACK-128 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7616 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
93766ee788
commit
c95c8b7e3a
10 changed files with 629 additions and 453 deletions
|
@ -22,6 +22,7 @@ package org.jivesoftware.smackx.filetransfer;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* An incoming file transfer is created when the
|
||||
|
@ -94,7 +95,7 @@ public class IncomingFileTransfer extends FileTransfer {
|
|||
* </UL>
|
||||
*
|
||||
* @param file The location to save the file.
|
||||
* @throws XMPPException when the file transfer fails
|
||||
* @throws XMPPException when the file transfer fails
|
||||
* @throws IllegalArgumentException This exception is thrown when the the provided file is
|
||||
* either null, or cannot be written to.
|
||||
*/
|
||||
|
@ -151,13 +152,13 @@ public class IncomingFileTransfer extends FileTransfer {
|
|||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch(Throwable io) {
|
||||
catch (Throwable io) {
|
||||
/* Ignore */
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
outputStream.close();
|
||||
}
|
||||
catch (Throwable io) {
|
||||
/* Ignore */
|
||||
|
@ -175,11 +176,34 @@ public class IncomingFileTransfer extends FileTransfer {
|
|||
|
||||
private InputStream negotiateStream() throws XMPPException {
|
||||
setStatus(Status.negotiating_transfer);
|
||||
StreamNegotiator streamNegotiator = negotiator
|
||||
final StreamNegotiator streamNegotiator = negotiator
|
||||
.selectStreamNegotiator(recieveRequest);
|
||||
setStatus(Status.negotiating_stream);
|
||||
InputStream inputStream = streamNegotiator
|
||||
.createIncomingStream(recieveRequest.getStreamInitiation());
|
||||
FutureTask<InputStream> streamNegotiatorTask = new FutureTask<InputStream>(
|
||||
new Callable<InputStream>() {
|
||||
|
||||
public InputStream call() throws Exception {
|
||||
return streamNegotiator
|
||||
.createIncomingStream(recieveRequest.getStreamInitiation());
|
||||
}
|
||||
});
|
||||
streamNegotiatorTask.run();
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = streamNegotiatorTask.get(15, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new XMPPException("Interruption while executing", e);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
throw new XMPPException("Error in execution", e);
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
throw new XMPPException("Request timed out", e);
|
||||
}
|
||||
finally {
|
||||
streamNegotiatorTask.cancel(true);
|
||||
}
|
||||
setStatus(Status.negotiated);
|
||||
return inputStream;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue