@Test public void upgradeAndDelete_createsDownloads() throws IOException { byte[] actionFileBytes = TestUtil.getByteArray( ApplicationProvider.getApplicationContext(), "offline/action_file_for_download_index_upgrade.exi"); try (FileOutputStream output = new FileOutputStream(tempFile)) { output.write(actionFileBytes); } StreamKey expectedStreamKey1 = new StreamKey( 3, 4, 5); StreamKey expectedStreamKey2 = new StreamKey( 0, 1, 2); DownloadRequest expectedRequest1 = new DownloadRequest( "key123", "test", Uri.parse("https: asList(expectedStreamKey1), "key123", new byte[] {1, 2, 3, 4}); DownloadRequest expectedRequest2 = new DownloadRequest( "key234", "test", Uri.parse("https: asList(expectedStreamKey2), "key234", new byte[] {5, 4, 3, 2, 1}); ActionFileUpgradeUtil.upgradeAndDelete( tempFile, null, downloadIndex, true, false); assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED); assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED); }
@SuppressWarnings("deprecation") public static void upgradeAndDelete( File actionFilePath, @Nullable DownloadIdProvider downloadIdProvider, DefaultDownloadIndex downloadIndex, boolean deleteOnFailure, boolean addNewDownloadsAsCompleted) throws IOException { ActionFile actionFile = new ActionFile(actionFilePath); if (actionFile.exists()) { boolean success = false; try { long nowMs = System.currentTimeMillis(); for (DownloadRequest request : actionFile.load()) { if (downloadIdProvider != null) { request = request.copyWithId(downloadIdProvider.getId(request)); } mergeRequest(request, downloadIndex, addNewDownloadsAsCompleted, nowMs); } success = true; } finally { if (success || deleteOnFailure) { actionFile.delete(); } } } }
ActionFileUpgradeUtil { @SuppressWarnings("deprecation") public static void upgradeAndDelete( File actionFilePath, @Nullable DownloadIdProvider downloadIdProvider, DefaultDownloadIndex downloadIndex, boolean deleteOnFailure, boolean addNewDownloadsAsCompleted) throws IOException { ActionFile actionFile = new ActionFile(actionFilePath); if (actionFile.exists()) { boolean success = false; try { long nowMs = System.currentTimeMillis(); for (DownloadRequest request : actionFile.load()) { if (downloadIdProvider != null) { request = request.copyWithId(downloadIdProvider.getId(request)); } mergeRequest(request, downloadIndex, addNewDownloadsAsCompleted, nowMs); } success = true; } finally { if (success || deleteOnFailure) { actionFile.delete(); } } } } }
ActionFileUpgradeUtil { @SuppressWarnings("deprecation") public static void upgradeAndDelete( File actionFilePath, @Nullable DownloadIdProvider downloadIdProvider, DefaultDownloadIndex downloadIndex, boolean deleteOnFailure, boolean addNewDownloadsAsCompleted) throws IOException { ActionFile actionFile = new ActionFile(actionFilePath); if (actionFile.exists()) { boolean success = false; try { long nowMs = System.currentTimeMillis(); for (DownloadRequest request : actionFile.load()) { if (downloadIdProvider != null) { request = request.copyWithId(downloadIdProvider.getId(request)); } mergeRequest(request, downloadIndex, addNewDownloadsAsCompleted, nowMs); } success = true; } finally { if (success || deleteOnFailure) { actionFile.delete(); } } } } private  ActionFileUpgradeUtil(); }
ActionFileUpgradeUtil { @SuppressWarnings("deprecation") public static void upgradeAndDelete( File actionFilePath, @Nullable DownloadIdProvider downloadIdProvider, DefaultDownloadIndex downloadIndex, boolean deleteOnFailure, boolean addNewDownloadsAsCompleted) throws IOException { ActionFile actionFile = new ActionFile(actionFilePath); if (actionFile.exists()) { boolean success = false; try { long nowMs = System.currentTimeMillis(); for (DownloadRequest request : actionFile.load()) { if (downloadIdProvider != null) { request = request.copyWithId(downloadIdProvider.getId(request)); } mergeRequest(request, downloadIndex, addNewDownloadsAsCompleted, nowMs); } success = true; } finally { if (success || deleteOnFailure) { actionFile.delete(); } } } } private  ActionFileUpgradeUtil(); @SuppressWarnings("deprecation") static void upgradeAndDelete(
      File actionFilePath,
      @Nullable DownloadIdProvider downloadIdProvider,
      DefaultDownloadIndex downloadIndex,
      boolean deleteOnFailure,
      boolean addNewDownloadsAsCompleted); }
ActionFileUpgradeUtil { @SuppressWarnings("deprecation") public static void upgradeAndDelete( File actionFilePath, @Nullable DownloadIdProvider downloadIdProvider, DefaultDownloadIndex downloadIndex, boolean deleteOnFailure, boolean addNewDownloadsAsCompleted) throws IOException { ActionFile actionFile = new ActionFile(actionFilePath); if (actionFile.exists()) { boolean success = false; try { long nowMs = System.currentTimeMillis(); for (DownloadRequest request : actionFile.load()) { if (downloadIdProvider != null) { request = request.copyWithId(downloadIdProvider.getId(request)); } mergeRequest(request, downloadIndex, addNewDownloadsAsCompleted, nowMs); } success = true; } finally { if (success || deleteOnFailure) { actionFile.delete(); } } } } private  ActionFileUpgradeUtil(); @SuppressWarnings("deprecation") static void upgradeAndDelete(
      File actionFilePath,
      @Nullable DownloadIdProvider downloadIdProvider,
      DefaultDownloadIndex downloadIndex,
      boolean deleteOnFailure,
      boolean addNewDownloadsAsCompleted);  }