Search in sources :

Example 6 with SendFileTransferException

use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.

the class AbstractUrlConnectionOutgoingFileTransfer method openStreams.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer#openStreams()
	 */
protected void openStreams() throws SendFileTransferException {
    try {
        File localFile = getFileTransferInfo().getFile();
        // Set input stream from local file
        setInputStream(new BufferedInputStream(new FileInputStream(localFile)));
        // Then connect
        connect();
        // Make PUT request
        setOutputStream(urlConnection.getOutputStream());
    } catch (final Exception e) {
        throw new SendFileTransferException(NLS.bind(Messages.UrlConnectionOutgoingFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) File(java.io.File) FileInputStream(java.io.FileInputStream) ProtocolException(java.net.ProtocolException) IOException(java.io.IOException) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException)

Example 7 with SendFileTransferException

use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.

the class LocalFileOutgoingFileTransfer method openStreams.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer#openStreams()
	 */
protected void openStreams() throws SendFileTransferException {
    IFileTransferInfo localFileTransferInfo = getFileTransferInfo();
    Assert.isNotNull(localFileTransferInfo);
    // Setup input file
    File inputFile = localFileTransferInfo.getFile();
    try {
        setInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
    } catch (Exception e) {
        hardClose();
        throw new SendFileTransferException(NLS.bind(Messages.LocalFileOutgoingFileTransfer_EXCEPTION_OPENING_FOR_INPUT, inputFile));
    }
    URL url = getRemoteFileURL();
    Assert.isNotNull(url);
    try {
        File outputFile = new File(url.getPath());
        setOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
    } catch (Exception e) {
        hardClose();
        throw new SendFileTransferException(NLS.bind(Messages.LocalFileOutgoingFileTransfer_EXCEPTION_OPENING_FOR_OUTPUT, url));
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IFileTransferInfo(org.eclipse.ecf.filetransfer.IFileTransferInfo) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) URL(java.net.URL)

Example 8 with SendFileTransferException

use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.

the class XMPPOutgoingFileTransferHelper method sendOutgoingRequest.

public void sendOutgoingRequest(IFileID targetReceiver, IFileTransferInfo localFileToSend, IFileTransferListener progressListener, Map options) throws SendFileTransferException {
    if (manager == null)
        throw new SendFileTransferException("not connected");
    if (!(targetReceiver instanceof XMPPFileID))
        throw new SendFileTransferException("target receiver not XMPPFileID type.");
    final XMPPFileID fileID = (XMPPFileID) targetReceiver;
    int requestTimeout = -1;
    if (options != null) {
        final Object option = options.get(OUTGOING_REQUEST_TIMEOUT);
        if (option != null) {
            if (option instanceof String) {
                try {
                    requestTimeout = Integer.valueOf((String) option).intValue();
                } catch (final NumberFormatException e) {
                // Ignore
                }
            } else if (option instanceof Integer) {
                requestTimeout = ((Integer) option).intValue();
            }
        }
    }
    final XMPPOutgoingFileTransfer fileTransfer = new XMPPOutgoingFileTransfer(manager, fileID.getXMPPID(), localFileToSend, progressListener, requestTimeout);
    try {
        fileTransfer.startSend(localFileToSend.getFile(), localFileToSend.getDescription());
    } catch (final XMPPException e) {
        throw new SendFileTransferException("Exception sending outgoing file transfer request", e);
    }
}
Also used : SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) XMPPException(org.jivesoftware.smack.XMPPException) XMPPFileID(org.eclipse.ecf.provider.xmpp.identity.XMPPFileID)

Aggregations

SendFileTransferException (org.eclipse.ecf.filetransfer.SendFileTransferException)8 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 MalformedURLException (java.net.MalformedURLException)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ISendFileTransferContainerAdapter (org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter)2 Session (com.jcraft.jsch.Session)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ProtocolException (java.net.ProtocolException)1 URI (java.net.URI)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFileTransferInfo (org.eclipse.ecf.filetransfer.IFileTransferInfo)1 XMPPFileID (org.eclipse.ecf.provider.xmpp.identity.XMPPFileID)1 XMPPException (org.jivesoftware.smack.XMPPException)1