public Builder toBuilder(String anotherUrl, Uri anotherUri) { final Builder builder = new Builder(anotherUrl, anotherUri) .setPriority(priority) .setReadBufferSize(readBufferSize) .setFlushBufferSize(flushBufferSize) .setSyncBufferSize(syncBufferSize) .setSyncBufferIntervalMillis(syncBufferIntervalMills) .setAutoCallbackToUIThread(autoCallbackToUIThread) .setMinIntervalMillisCallbackProcess(minIntervalMillisCallbackProcess) .setHeaderMapFields(headerMapFields) .setPassIfAlreadyCompleted(passIfAlreadyCompleted); // check whether the filename is special set from method. if (Util.isUriFileScheme(anotherUri) // only if another uri is file-scheme && !new File(anotherUri.getPath()).isFile() // another uri is not file already && Util.isUriFileScheme(uri) // only if uri is file-scheme // only if filename is provided and not provided through uri && filenameHolder.get() != null && !new File(uri.getPath()).getName().equals(filenameHolder.get()) ) { builder.setFilename(filenameHolder.get()); } return builder; }
@Test public void toBuilder() { // filename is provided specially => set filename final Uri uri = mock(Uri.class); when(uri.getPath()).thenReturn(parentPath); when(uri.getScheme()).thenReturn(ContentResolver.SCHEME_FILE); DownloadTask task = new DownloadTask .Builder("url", uri) .setFilename("filename1") .build(); DownloadTask buildTask = task.toBuilder().build(); assertThat(buildTask.getUrl()).isEqualTo("url"); assertThat(buildTask.getUri()).isEqualTo(uri); assertThat(buildTask.getFilename()).isEqualTo("filename1"); // another uri is file, use new filename final Uri anotherUri = mock(Uri.class); when(anotherUri.getScheme()).thenReturn(ContentResolver.SCHEME_FILE); when(anotherUri.getPath()).thenReturn(parentPath + filename); buildTask = task.toBuilder("anotherUrl", anotherUri).build(); assertThat(buildTask.getUrl()).isEqualTo("anotherUrl"); assertThat(buildTask.getUri()).isEqualTo(anotherUri); assertThat(buildTask.getFilename()).isEqualTo(filename); // same uri provided filename => same file when(uri.getPath()).thenReturn(parentPath + filename); task = new DownloadTask .Builder("url", uri) .build(); buildTask = task.toBuilder("anotherUrl", uri).build(); assertFile(buildTask.getFile()).isEqualTo(task.getFile()); }
.setFilename(filename) .build(); .setFilename("another-filename") .build(); .setFilename("another-filename") .build(); assertThat(noFilenameTask.equals(anotherTask)).isFalse(); .setFilename("response-filename") .build(); assertThat(noFilenameTask.equals(anotherTask)).isTrue();
.setFilename(filename) .build(); assertThat(task.getFilename()).isEqualTo(filename);
private void initTask() { final String filename = "single-test"; final String url = "https://cdn.llscdn.com/yy/files/xs8qmxn8-lls-LLS-5.8-800-20171207-111607.apk"; final File parentFile = DemoUtil.getParentFile(this); task = new DownloadTask.Builder(url, parentFile) .setFilename(filename) // the minimal interval millisecond for callback progress .setMinIntervalMillisCallbackProcess(16) // ignore the same task has already completed in the past. .setPassIfAlreadyCompleted(false) .build(); }
private void initTask() { task = new DownloadTask .Builder(DemoUtil.URL, DemoUtil.getParentFile(this)) .setFilename("notification-file.apk") // if there is the same task has been completed download, just delete it and // re-download automatically. .setPassIfAlreadyCompleted(false) .setMinIntervalMillisCallbackProcess(80) // because for the notification we don't need make sure invoke on the ui thread, so // just let callback no need callback to the ui thread. .setAutoCallbackToUIThread(false) .build(); }
private DownloadTask createTask(String url) { final String filename = "each-block-progress-test"; final File parentFile = DemoUtil.getParentFile(this); return new DownloadTask.Builder(url, parentFile) .setFilename(filename) // the minimal interval millisecond for callback progress .setMinIntervalMillisCallbackProcess(64) // ignore the same task has already completed in the past. .setPassIfAlreadyCompleted(false) .build(); }