mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Merge branch 'filetransferTypos' into jingle2
This commit is contained in:
commit
a11552eb63
8 changed files with 41 additions and 41 deletions
|
@ -35,7 +35,7 @@ import org.jxmpp.jid.Jid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fault tolerant negotiator takes two stream negotiators, the primary and the secondary
|
* The fault tolerant negotiator takes two stream negotiators, the primary and the secondary
|
||||||
* negotiator. If the primary negotiator fails during the stream negotiaton process, the second
|
* negotiator. If the primary negotiator fails during the stream negotiation process, the second
|
||||||
* negotiator is used.
|
* negotiator is used.
|
||||||
*/
|
*/
|
||||||
public class FaultTolerantNegotiator extends StreamNegotiator {
|
public class FaultTolerantNegotiator extends StreamNegotiator {
|
||||||
|
@ -78,7 +78,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
|
||||||
} else if (streamInitiation instanceof Open) {
|
} else if (streamInitiation instanceof Open) {
|
||||||
return secondaryNegotiator;
|
return secondaryNegotiator;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unknown stream initation type");
|
throw new IllegalStateException("Unknown stream initiation type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,18 +77,18 @@ public abstract class FileTransfer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of the file being transfered.
|
* Returns the size of the file being transferred.
|
||||||
*
|
*
|
||||||
* @return Returns the size of the file being transfered.
|
* @return Returns the size of the file being transferred.
|
||||||
*/
|
*/
|
||||||
public long getFileSize() {
|
public long getFileSize() {
|
||||||
return fileSize;
|
return fileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the file being transfered.
|
* Returns the name of the file being transferred.
|
||||||
*
|
*
|
||||||
* @return Returns the name of the file being transfered.
|
* @return Returns the name of the file being transferred.
|
||||||
*/
|
*/
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
|
@ -247,7 +247,7 @@ public abstract class FileTransfer {
|
||||||
* The file transfer is being negotiated with the peer. The party
|
* The file transfer is being negotiated with the peer. The party
|
||||||
* Receiving the file has the option to accept or refuse a file transfer
|
* Receiving the file has the option to accept or refuse a file transfer
|
||||||
* request. If they accept, then the process of stream negotiation will
|
* request. If they accept, then the process of stream negotiation will
|
||||||
* begin. If they refuse the file will not be transfered.
|
* begin. If they refuse the file will not be transferred.
|
||||||
*
|
*
|
||||||
* @see #negotiating_stream
|
* @see #negotiating_stream
|
||||||
*/
|
*/
|
||||||
|
@ -294,7 +294,7 @@ public abstract class FileTransfer {
|
||||||
|
|
||||||
private final String status;
|
private final String status;
|
||||||
|
|
||||||
private Status(String status) {
|
Status(String status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,16 +337,16 @@ public abstract class FileTransfer {
|
||||||
/**
|
/**
|
||||||
* An error occurred over the socket connected to send the file.
|
* An error occurred over the socket connected to send the file.
|
||||||
*/
|
*/
|
||||||
connection("An error occured over the socket connected to send the file."),
|
connection("An error occurred over the socket connected to send the file."),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An error occurred while sending or receiving the file.
|
* An error occurred while sending or receiving the file.
|
||||||
*/
|
*/
|
||||||
stream("An error occured while sending or recieving the file.");
|
stream("An error occurred while sending or receiving the file.");
|
||||||
|
|
||||||
private final String msg;
|
private final String msg;
|
||||||
|
|
||||||
private Error(String msg) {
|
Error(String msg) {
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@ package org.jivesoftware.smackx.filetransfer;
|
||||||
*/
|
*/
|
||||||
public interface FileTransferListener {
|
public interface FileTransferListener {
|
||||||
/**
|
/**
|
||||||
* A request to send a file has been recieved from another user.
|
* A request to send a file has been received from another user.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* The request from the other user.
|
* The request from the other user.
|
||||||
*/
|
*/
|
||||||
public void fileTransferRequest(final FileTransferRequest request);
|
void fileTransferRequest(final FileTransferRequest request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,10 @@ import org.jivesoftware.smackx.si.packet.StreamInitiation;
|
||||||
import org.jxmpp.jid.EntityFullJid;
|
import org.jxmpp.jid.EntityFullJid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file transfer manager class handles the sending and recieving of files.
|
* The file transfer manager class handles the sending and receiving of files.
|
||||||
* To send a file invoke the {@link #createOutgoingFileTransfer(EntityFullJid)} method.
|
* To send a file invoke the {@link #createOutgoingFileTransfer(EntityFullJid)} method.
|
||||||
* <p>
|
* <p>
|
||||||
* And to recieve a file add a file transfer listener to the manager. The
|
* And to receive a file add a file transfer listener to the manager. The
|
||||||
* listener will notify you when there is a new file transfer request. To create
|
* listener will notify you when there is a new file transfer request. To create
|
||||||
* the {@link IncomingFileTransfer} object accept the transfer, or, if the
|
* the {@link IncomingFileTransfer} object accept the transfer, or, if the
|
||||||
* transfer is not desirable reject it.
|
* transfer is not desirable reject it.
|
||||||
|
@ -135,7 +135,7 @@ public final class FileTransferManager extends Manager {
|
||||||
/**
|
/**
|
||||||
* When the file transfer request is acceptable, this method should be
|
* When the file transfer request is acceptable, this method should be
|
||||||
* invoked. It will create an IncomingFileTransfer which allows the
|
* invoked. It will create an IncomingFileTransfer which allows the
|
||||||
* transmission of the file to procede.
|
* transmission of the file to proceed.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* The remote request that is being accepted.
|
* The remote request that is being accepted.
|
||||||
|
@ -145,7 +145,7 @@ public final class FileTransferManager extends Manager {
|
||||||
protected IncomingFileTransfer createIncomingFileTransfer(
|
protected IncomingFileTransfer createIncomingFileTransfer(
|
||||||
FileTransferRequest request) {
|
FileTransferRequest request) {
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
throw new NullPointerException("RecieveRequest cannot be null");
|
throw new NullPointerException("ReceiveRequest cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
IncomingFileTransfer transfer = new IncomingFileTransfer(request,
|
IncomingFileTransfer transfer = new IncomingFileTransfer(request,
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.jivesoftware.smackx.si.packet.StreamInitiation;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A request to send a file recieved from another user.
|
* A request to send a file received from another user.
|
||||||
*
|
*
|
||||||
* @author Alexander Wenckus
|
* @author Alexander Wenckus
|
||||||
*
|
*
|
||||||
|
@ -34,14 +34,14 @@ public class FileTransferRequest {
|
||||||
private final FileTransferManager manager;
|
private final FileTransferManager manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A recieve request is constructed from the Stream Initiation request
|
* A receive request is constructed from the Stream Initiation request
|
||||||
* received from the initator.
|
* received from the initiator.
|
||||||
*
|
*
|
||||||
* @param manager
|
* @param manager
|
||||||
* The manager handling this file transfer
|
* The manager handling this file transfer
|
||||||
*
|
*
|
||||||
* @param si
|
* @param si
|
||||||
* The Stream initiaton recieved from the initiator.
|
* The Stream initiation received from the initiator.
|
||||||
*/
|
*/
|
||||||
public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
|
public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
|
||||||
this.streamInitiation = si;
|
this.streamInitiation = si;
|
||||||
|
@ -67,9 +67,9 @@ public class FileTransferRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the description of the file provided by the requestor.
|
* Returns the description of the file provided by the requester.
|
||||||
*
|
*
|
||||||
* @return Returns the description of the file provided by the requestor.
|
* @return Returns the description of the file provided by the requester.
|
||||||
*/
|
*/
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return streamInitiation.getFile().getDesc();
|
return streamInitiation.getFile().getDesc();
|
||||||
|
@ -106,12 +106,12 @@ public class FileTransferRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the stream initiation stanza(/packet) that was sent by the requestor which
|
* Returns the stream initiation stanza(/packet) that was sent by the requester which
|
||||||
* contains the parameters of the file transfer being transfer and also the
|
* contains the parameters of the file transfer being transfer and also the
|
||||||
* methods available to transfer the file.
|
* methods available to transfer the file.
|
||||||
*
|
*
|
||||||
* @return Returns the stream initiation stanza(/packet) that was sent by the
|
* @return Returns the stream initiation stanza(/packet) that was sent by the
|
||||||
* requestor which contains the parameters of the file transfer
|
* requester which contains the parameters of the file transfer
|
||||||
* being transfer and also the methods available to transfer the
|
* being transfer and also the methods available to transfer the
|
||||||
* file.
|
* file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -43,13 +43,13 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
* concerned with and they can be handled in different ways depending upon the
|
* concerned with and they can be handled in different ways depending upon the
|
||||||
* method that is invoked on this class.
|
* method that is invoked on this class.
|
||||||
* <p/>
|
* <p/>
|
||||||
* The first way that a file is recieved is by calling the
|
* The first way that a file is received is by calling the
|
||||||
* {@link #recieveFile()} method. This method, negotiates the appropriate stream
|
* {@link #receiveFile()} method. This method, negotiates the appropriate stream
|
||||||
* method and then returns the <b><i>InputStream</b></i> to read the file
|
* method and then returns the <b><i>InputStream</b></i> to read the file
|
||||||
* data from.
|
* data from.
|
||||||
* <p/>
|
* <p/>
|
||||||
* The second way that a file can be recieved through this class is by invoking
|
* The second way that a file can be received through this class is by invoking
|
||||||
* the {@link #recieveFile(File)} method. This method returns immediatly and
|
* the {@link #receiveFile(File)} method. This method returns immediately and
|
||||||
* takes as its parameter a file on the local file system where the file
|
* takes as its parameter a file on the local file system where the file
|
||||||
* recieved from the transfer will be put.
|
* recieved from the transfer will be put.
|
||||||
*
|
*
|
||||||
|
@ -59,14 +59,14 @@ public class IncomingFileTransfer extends FileTransfer {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(IncomingFileTransfer.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(IncomingFileTransfer.class.getName());
|
||||||
|
|
||||||
private FileTransferRequest recieveRequest;
|
private FileTransferRequest receiveRequest;
|
||||||
|
|
||||||
private InputStream inputStream;
|
private InputStream inputStream;
|
||||||
|
|
||||||
protected IncomingFileTransfer(FileTransferRequest request,
|
protected IncomingFileTransfer(FileTransferRequest request,
|
||||||
FileTransferNegotiator transferNegotiator) {
|
FileTransferNegotiator transferNegotiator) {
|
||||||
super(request.getRequestor(), request.getStreamID(), transferNegotiator);
|
super(request.getRequestor(), request.getStreamID(), transferNegotiator);
|
||||||
this.recieveRequest = request;
|
this.receiveRequest = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +79,7 @@ public class IncomingFileTransfer extends FileTransfer {
|
||||||
* is thrown.
|
* is thrown.
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public InputStream recieveFile() throws SmackException, XMPPErrorException, InterruptedException {
|
public InputStream receiveFile() throws SmackException, XMPPErrorException, InterruptedException {
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
throw new IllegalStateException("Transfer already negotiated!");
|
throw new IllegalStateException("Transfer already negotiated!");
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,10 @@ public class IncomingFileTransfer extends FileTransfer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method negotitates the stream and then transfer's the file over the negotiated stream.
|
* This method negotiates the stream and then transfer's the file over the negotiated stream.
|
||||||
* The transfered file will be saved at the provided location.
|
* The transferred file will be saved at the provided location.
|
||||||
* <p/>
|
* <p/>
|
||||||
* This method will return immedialtly, file transfer progress can be monitored through several
|
* This method will return immediately, file transfer progress can be monitored through several
|
||||||
* methods:
|
* methods:
|
||||||
* <p/>
|
* <p/>
|
||||||
* <UL>
|
* <UL>
|
||||||
|
@ -114,7 +114,7 @@ public class IncomingFileTransfer extends FileTransfer {
|
||||||
* @throws IllegalArgumentException This exception is thrown when the the provided file is
|
* @throws IllegalArgumentException This exception is thrown when the the provided file is
|
||||||
* either null, or cannot be written to.
|
* either null, or cannot be written to.
|
||||||
*/
|
*/
|
||||||
public void recieveFile(final File file) throws SmackException, IOException {
|
public void receiveFile(final File file) throws SmackException, IOException {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new IllegalArgumentException("File cannot be null");
|
throw new IllegalArgumentException("File cannot be null");
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ public class IncomingFileTransfer extends FileTransfer {
|
||||||
private InputStream negotiateStream() throws SmackException, XMPPErrorException, InterruptedException {
|
private InputStream negotiateStream() throws SmackException, XMPPErrorException, InterruptedException {
|
||||||
setStatus(Status.negotiating_transfer);
|
setStatus(Status.negotiating_transfer);
|
||||||
final StreamNegotiator streamNegotiator = negotiator
|
final StreamNegotiator streamNegotiator = negotiator
|
||||||
.selectStreamNegotiator(recieveRequest);
|
.selectStreamNegotiator(receiveRequest);
|
||||||
setStatus(Status.negotiating_stream);
|
setStatus(Status.negotiating_stream);
|
||||||
FutureTask<InputStream> streamNegotiatorTask = new FutureTask<InputStream>(
|
FutureTask<InputStream> streamNegotiatorTask = new FutureTask<InputStream>(
|
||||||
new Callable<InputStream>() {
|
new Callable<InputStream>() {
|
||||||
|
@ -188,7 +188,7 @@ public class IncomingFileTransfer extends FileTransfer {
|
||||||
@Override
|
@Override
|
||||||
public InputStream call() throws Exception {
|
public InputStream call() throws Exception {
|
||||||
return streamNegotiator
|
return streamNegotiator
|
||||||
.createIncomingStream(recieveRequest.getStreamInitiation());
|
.createIncomingStream(receiveRequest.getStreamInitiation());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
streamNegotiatorTask.run();
|
streamNegotiatorTask.run();
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
String description) throws XMPPException, SmackException, InterruptedException {
|
String description) throws XMPPException, SmackException, InterruptedException {
|
||||||
if (isDone() || outputStream != null) {
|
if (isDone() || outputStream != null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"The negotation process has already"
|
"The negotiation process has already"
|
||||||
+ " been attempted on this file transfer");
|
+ " been attempted on this file transfer");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -169,7 +169,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
checkTransferThread();
|
checkTransferThread();
|
||||||
if (isDone() || outputStream != null) {
|
if (isDone() || outputStream != null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"The negotation process has already"
|
"The negotiation process has already"
|
||||||
+ " been attempted for this file transfer");
|
+ " been attempted for this file transfer");
|
||||||
}
|
}
|
||||||
setFileInfo(fileName, fileSize);
|
setFileInfo(fileName, fileSize);
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class FileTransferIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
byte[] dataReceived = null;
|
byte[] dataReceived = null;
|
||||||
IncomingFileTransfer ift = request.accept();
|
IncomingFileTransfer ift = request.accept();
|
||||||
try {
|
try {
|
||||||
InputStream is = ift.recieveFile();
|
InputStream is = ift.receiveFile();
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
int nRead;
|
int nRead;
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
|
|
Loading…
Reference in a new issue