public void registerProxyTransfer(String transferDigest, ProxyTransfer proxyTransfer) throws UnauthorizedException { FileTransfer transfer = retrieveFileTransfer(transferDigest); if (isMatchProxyTransfer() && transfer == null) { throw new UnauthorizedException("Unable to match proxy transfer with a file transfer"); } else if (transfer == null) { return; } transfer.setProgress(proxyTransfer); cacheFileTransfer(transferDigest, transfer); }
public boolean acceptIncomingFileTransferRequest(FileTransfer transfer) throws FileTransferRejectedException { fireFileTransferIntercept(transfer, false); if (transfer != null) { String streamID = transfer.getSessionID(); JID from = new JID(transfer.getInitiator()); JID to = new JID(transfer.getTarget()); cacheFileTransfer(ProxyConnectionManager.createDigest(streamID, from, to), transfer); return true; } return false; }
public void doDownload(HttpServletRequest req, HttpServletResponse resp, int hc) throws IOException { FileTransfer ft = FileTransfer.get(hc); if (ft == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } resp.setContentType(ft.mimeType); if (ft.size > 0) resp.setContentLength((int) ft.size); /*if (ft.filename != null) { resp.setHeader("Content-Disposition", (ft.inline ? "inline" : "attachment") + ";filename=" + ft.filename); }*/ resp.setHeader( "Content-Disposition", (ft.inline ? "inline" : "attachment") + (ft.filename != null ? ";filename=" + ft.filename : "")); if (ft.size < 0) resp.setHeader("Transfer-Encoding", "chunked"); else resp.setHeader("Content-Transfer-Encoding", "binary"); resp.setHeader("Expires", "0"); resp.setHeader("Cache-Control", "must-revalidate"); InputStream in = null; OutputStream out = null; try { in = ft.getInputStream(); out = resp.getOutputStream(); boolean te = ft.size < 0; byte[] buffer = new byte[4096]; while (true) { int n = in.read(buffer); if (n <= 0) break; if (te) { out.write(Integer.toHexString(n).getBytes()); out.write(13); out.write(10); } out.write(buffer, 0, n); if (te) { out.write(13); out.write(10); } } if (te) out.write("0\r\n\r\n".getBytes()); out.flush(); } catch (Error er) { logger.log(Level.SEVERE, er.getLocalizedMessage()); } finally { if (in != null) in.close(); if (out != null) out.close(); } }
/** * Handles buttons action events. * * @param evt the <tt>ActionEvent</tt> that notified us */ public void actionPerformed(ActionEvent evt) { JButton sourceButton = (JButton) evt.getSource(); if (sourceButton.equals(openFileButton)) { this.openFile(downloadFile); } else if (sourceButton.equals(openFolderButton)) { try { File downloadDir = GuiActivator.getFileAccessService().getDefaultDownloadDirectory(); GuiActivator.getDesktopService().open(downloadDir); } catch (IllegalArgumentException e) { if (logger.isDebugEnabled()) logger.debug("Unable to open folder.", e); this.showErrorMessage(resources.getI18NString("service.gui.FOLDER_DOES_NOT_EXIST")); } catch (NullPointerException e) { if (logger.isDebugEnabled()) logger.debug("Unable to open folder.", e); this.showErrorMessage(resources.getI18NString("service.gui.FOLDER_DOES_NOT_EXIST")); } catch (UnsupportedOperationException e) { if (logger.isDebugEnabled()) logger.debug("Unable to open folder.", e); this.showErrorMessage(resources.getI18NString("service.gui.FILE_OPEN_NOT_SUPPORTED")); } catch (SecurityException e) { if (logger.isDebugEnabled()) logger.debug("Unable to open folder.", e); this.showErrorMessage(resources.getI18NString("service.gui.FOLDER_OPEN_NO_PERMISSION")); } catch (IOException e) { if (logger.isDebugEnabled()) logger.debug("Unable to open folder.", e); this.showErrorMessage(resources.getI18NString("service.gui.FOLDER_OPEN_NO_APPLICATION")); } catch (Exception e) { if (logger.isDebugEnabled()) logger.debug("Unable to open file.", e); this.showErrorMessage(resources.getI18NString("service.gui.FOLDER_OPEN_FAILED")); } } else if (sourceButton.equals(cancelButton)) { if (fileTransfer != null) fileTransfer.cancel(); } }
/** * Sets the file transfer. * * @param fileTransfer the file transfer * @param transferredFileSize the size of the transferred file */ protected void setFileTransfer(FileTransfer fileTransfer, long transferredFileSize) { this.fileTransfer = fileTransfer; this.transferredFileSize = transferredFileSize; fileTransfer.addProgressListener(this); }