public class MyClass { public void doSomething() { FileDownloader downloader = new FileDownloader(); downloader.setListener(new IAsyncFetchListener() { public void onComplete(String item) { // do something with item } public void onError(Throwable error) { // report error } }); downloader.start(); } }
/** * Gets the resource set for download. * * @return the resource that will be downloaded if clicking the extended * component */ public Resource getFileDownloadResource() { return getResource("dl"); }
menuBar.addItem("Download", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { FileDownloader fileDownloader = new FileDownloader(...); fileDownloader.extend(downloadInvisibleButton); //Simulate the click on downloadInvisibleButton by JavaScript Page.getCurrent().getJavaScript() .execute("document.getElementById('DownloadButtonId').click();"); } });
Button l = new Button("Link to pdf"); StreamResource sr = getPDFStream(); FileDownloader fileDownloader = new FileDownloader(sr); fileDownloader.extend(l);
List<String> hosts = fetchTargetHosts(); FileDownloader fileDownloader = new FileDownloader(); for(String host: hosts) CompletableFuture.runAsync(()-> new HostDownloader(host).get().forEach(fileDownloader));
@Override protected Void call() throws Exception { FileDownloader downloader = new FileDownloader(); downloader.bytesDownloadedProperty().addListener((obs, oldValue, newValue) -> updateProgress(newValue.longValue(), downloader.getTotalBytes())); boolean isDownloaded = downloader.downloadSysVersion(); // ... }
@Override protected Void call() throws Exception { FileDownloader downloader = new FileDownloader(); downloader.setProgressUpdate(bytesDownloaded -> updateProgress(bytesDownloaded, downloader.getTotalBytes())); boolean isDownloaded = downloader.downloadSysVersion(); // ... }
FileDownloader fdl = new FileDownloader(this); fdl.execute(...);
VaadinSession session = getSession(); Resource resource = getFileDownloadResource(); if (!(resource instanceof ConnectorResource)) { return false; if (isOverrideContentType()) { stream.setContentType("application/octet-stream;charset=UTF-8");
/** * Add this extension to the {@code EventTrigger}. * * @param eventTrigger * the trigger to attach this extension to * @since 8.4 */ public void extend(EventTrigger eventTrigger) { super.extend(eventTrigger.getConnector()); getState().partInformation = eventTrigger.getPartInformation(); }
FileDownloader f = new FileDownloader(new StreamResource(null, null)) { @Override public Resource getFileDownloadResource() { tmpFileErzeuger.erzeugeXMLDatei(selectedItems); return new FileResource(tmpFileErzeuger.addToZipFile()); } }; f.extend(downloadButton);
FileResource resource = new FileResource(pdfFile); FileDownloader downloader = new FileDownloader(resource); Button pdf= new Button("Download PDF"); downloader.extend(pdf);
private void doDownload() { // Retrieve the FileDownloader instance if previousy retained fdl = (FileDownloader)getLastNonConfigurationInstance(); // If it's not null, set the Context to use for progress updates and // to manipulate any UI elements in onPostExecute(...) if (fdl != null) fdl.setParentActivity(this); else { // If we got here fdl is null so an instance hasn't been retained String[] downloadFileList = this.getResources().getStringArray(R.array.full_download_file_list); fdl = new FileDownloader(this); fdl.execute(downloadFileList); } }
/** * @param mappingConfiguration the mappingConfiguration to set */ public void setMappingConfiguration(MappingConfiguration mappingConfiguration) { this.mappingConfiguration = mappingConfiguration; this.loadParameterNames(); FileDownloader fd = new FileDownloader(this.getMappingConfigurationExportStream()); fd.extend(exportMappingConfigurationButton); FileDownloader fdValues = new FileDownloader(this.getMappingConfigurationValuesExportStream()); fdValues.extend(exportMappingConfigurationValuesButton); this.mappingConfigurationConfigurationValuesTable.populateTable(mappingConfiguration); } }
Button downloadButton = new Button("Download image"); StreamResource myResource = createResource(); FileDownloader fileDownloader = new FileDownloader(myResource); fileDownloader.extend(downloadButton);
List<String> hosts = fetchTargetHosts(); int concurrentHosts = 10; int concurrentConnections = 100; ExecutorService hostEs=Executors.newWorkStealingPool(concurrentHosts); ExecutorService connEs=Executors.newWorkStealingPool(concurrentConnections); FileDownloader fileDownloader = new FileDownloader(); for(String host: hosts) hostEs.execute(()-> { for(String target: new HostDownloader(host).get()) connEs.execute(()->fileDownloader.accept(target)); });
{ final Button downloadButton = new Button("Download file"); final StreamResource stream = new StreamResource( new StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream("Hola".getBytes()); } }, "badname.txt"); FileDownloader downloader = new FileDownloader(stream) { @Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { stream.setFilename("better-name.txt"); return super .handleConnectorRequest(request, response, path); } }; downloader.extend(downloadButton); layout.addComponent(downloadButton); }
Button btn = new Button("Download"); layout.addComponent(btn); Resource res = new FileResource(new File("/tmp/file.pdf")); FileDownloader fd = new FileDownloader(res); fd.extend(btn);
new FileDownloader(mActivity, fileUrl, fileName) { @Override protected void onPostExecute(Boolean result) {
fileDownloader = new FileDownloader(new Resource() { @Override public String getMIMEType() { fileDownloader.extend(buttonPanel.getNext());