@Test public void mergeRequest_existingDownload_createsMergedDownload() throws IOException { StreamKey streamKey1 = new StreamKey( 3, 4, 5); StreamKey streamKey2 = new StreamKey( 0, 1, 2); DownloadRequest request1 = new DownloadRequest( "id", TYPE_PROGRESSIVE, Uri.parse("https: asList(streamKey1), "key123", new byte[] {1, 2, 3, 4}); DownloadRequest request2 = new DownloadRequest( "id", TYPE_PROGRESSIVE, Uri.parse("https: asList(streamKey2), "key123", new byte[] {5, 4, 3, 2, 1}); ActionFileUpgradeUtil.mergeRequest( request1, downloadIndex, false, NOW_MS); ActionFileUpgradeUtil.mergeRequest( request2, downloadIndex, false, NOW_MS); Download download = downloadIndex.getDownload(request2.id); assertThat(download).isNotNull(); assertThat(download.request.type).isEqualTo(request2.type); assertThat(download.request.customCacheKey).isEqualTo(request2.customCacheKey); assertThat(download.request.data).isEqualTo(request2.data); assertThat(download.request.uri).isEqualTo(request2.uri); assertThat(download.request.streamKeys).containsExactly(streamKey1, streamKey2); assertThat(download.state).isEqualTo(Download.STATE_QUEUED); }
static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } private  ActionFileUpgradeUtil(); }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } private  ActionFileUpgradeUtil(); @SuppressWarnings("deprecation") static void upgradeAndDelete(
      File actionFilePath,
      @Nullable DownloadIdProvider downloadIdProvider,
      DefaultDownloadIndex downloadIndex,
      boolean deleteOnFailure,
      boolean addNewDownloadsAsCompleted); }
ActionFileUpgradeUtil { static void mergeRequest( DownloadRequest request, DefaultDownloadIndex downloadIndex, boolean addNewDownloadAsCompleted, long nowMs) throws IOException { Download download = downloadIndex.getDownload(request.id); if (download != null) { download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); } else { download = new Download( request, addNewDownloadAsCompleted ? Download.STATE_COMPLETED : STATE_QUEUED, nowMs, nowMs, C.LENGTH_UNSET, Download.STOP_REASON_NONE, Download.FAILURE_REASON_NONE); } downloadIndex.putDownload(download); } private  ActionFileUpgradeUtil(); @SuppressWarnings("deprecation") static void upgradeAndDelete(
      File actionFilePath,
      @Nullable DownloadIdProvider downloadIdProvider,
      DefaultDownloadIndex downloadIndex,
      boolean deleteOnFailure,
      boolean addNewDownloadsAsCompleted);  }