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(); } }
List<String> hosts = fetchTargetHosts(); FileDownloader fileDownloader = new FileDownloader(); for(String host: hosts) CompletableFuture.runAsync(()-> new HostDownloader(host).get().forEach(fileDownloader));
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); } }
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();"); } });
FileDownloader fdl = new FileDownloader(this); fdl.execute(...);
FileDownloader f = new FileDownloader(new StreamResource(null, null)) { @Override public Resource getFileDownloadResource() { tmpFileErzeuger.erzeugeXMLDatei(selectedItems); return new FileResource(tmpFileErzeuger.addToZipFile()); } }; f.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)); });
@Override protected Void call() throws Exception { FileDownloader downloader = new FileDownloader(); downloader.setProgressUpdate(bytesDownloaded -> updateProgress(bytesDownloaded, downloader.getTotalBytes())); boolean isDownloaded = downloader.downloadSysVersion(); // ... }
@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(); // ... }
/** * @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); } }
{ 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); }
fileDownloader = new FileDownloader(new Resource() { @Override public String getMIMEType() {
fileDownloader = new FileDownloader(new Resource() { @Override public String getMIMEType() {
new FileDownloader(mActivity, fileUrl, fileName) { @Override protected void onPostExecute(Boolean result) {
exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); FileDownloader fd = new FileDownloader(this.getModuleConfigurationExportStream(module)); fd.extend(exportMappingConfigurationButton);
exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); FileDownloader fd = new FileDownloader(this.getFlowConfigurationExportStream(flow)); fd.extend(exportMappingConfigurationButton);
FileDownloader fd = new FileDownloader(getMappingConfigurationExportStream(mappingConfiguration)); fd.extend(exportMappingConfigurationButton);
FileDownloader fd = new FileDownloader(this.getPayloadDownloadStream()); fd.extend(downloadButton);
FileDownloader fd = new FileDownloader(this.getPayloadDownloadStream()); fd.extend(downloadButton);
FileDownloader fd = new FileDownloader(this.getPayloadDownloadStream()); fd.extend(downloadButton);