• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.libraries.mobiledatadownload.internal.downloader;
17 
18 import android.net.Uri;
19 
20 /** Delta file name utility class. */
21 public class FileNameUtil {
22 
23   public static final String NAME_SEPARATOR = "_";
24 
25   /**
26    * For cases that the downloaded file is different than the final file, generate a temporary file
27    * for download and name it with a suffix of the downloaded file checksum to avoid naming
28    * conflicts.
29    */
getTempFileNameWithDownloadedFileChecksum(String fileName, String checksum)30   public static String getTempFileNameWithDownloadedFileChecksum(String fileName, String checksum) {
31     return fileName + NAME_SEPARATOR + checksum;
32   }
33 
34   /** Get the final file name by removing the temporary downloaded file suffix as "_checksum". */
getFinalFileUriWithTempDownloadedFile(Uri downloadedFileUri)35   public static Uri getFinalFileUriWithTempDownloadedFile(Uri downloadedFileUri) {
36     String serializedDeltaFileUri = downloadedFileUri.toString();
37     return Uri.parse(
38         serializedDeltaFileUri.substring(0, serializedDeltaFileUri.lastIndexOf(NAME_SEPARATOR)));
39   }
40 }
41