Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.
         
       
     
  
  
  
  
  
    
    
      
    
    
      
      Stay organized with collections
    
    
      
      Save and categorize content based on your preferences.
    
  
  
    
  
  
  
  
    
  
  
    
    
  
  
GCSFileDownloader
  public
  
  
  
  class
  GCSFileDownloader
  
  
  
  
  
  
  
    extends GCSFileDownloaderBase
  
  
  
  
  
      implements
      
        IFileDownloader
      
  
  
  
    
  File downloader to download file from google cloud storage (GCS).
Summary
| Public methods | 
|---|
  
  
  
    | 
        
        
        static
        
        
        File | 
      createTempFileForRemote(String remoteFilePath, File rootDir)
       | 
  
  
  
  
    | 
        
        
        
        
        
        void | 
      downloadFile(String remotePath, File destFile)
       | 
  
  
  
  
    | 
        
        
        
        
        
        File | 
      downloadFile(String remoteFilePath)
      Download file from GCS.
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      isFresh(File localFile, String remotePath)
      Check local file's freshness.
        
    
 | 
  
| Protected methods | 
|---|
  
  
  
    | 
        
        
        
        
        
        void | 
      clearCache()
       | 
  
  
  
  
    | 
        
        
        
        
        
        void | 
      downloadFile(String bucketName, String remoteFilename, File localFile)
       | 
  
  
  
  
    | 
        
        
        
        
        
        Storage | 
      getStorage( scopes)
      Override the implementation in base to support credential based on TF options.
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        String[] | 
      parseGcsPath(String remotePath)
       | 
  
Public constructors
    GCSFileDownloader
    
public GCSFileDownloader ()
    
    
    
  
 
    GCSFileDownloader
    
public GCSFileDownloader (Boolean createEmptyFile)
    
    
    
  
    
    | Parameters | 
|---|
      
        | createEmptyFile | Boolean | 
    
 
    GCSFileDownloader
    
public GCSFileDownloader (File jsonKeyFile)
    
    
    
  
    
    | Parameters | 
|---|
      
        | jsonKeyFile | File | 
    
 
    GCSFileDownloader
    
public GCSFileDownloader (File jsonKeyFile, 
                Boolean createEmptyFile)
    
    
    
  
    
    | Parameters | 
|---|
      
        | jsonKeyFile | File | 
      
        | createEmptyFile | Boolean | 
    
 
Public methods
    createTempFileForRemote
    
public static File createTempFileForRemote (String remoteFilePath, 
                File rootDir)
    
    
    
  
    
    | Parameters | 
|---|
      
        | remoteFilePath | String | 
      
        | rootDir | File | 
    
    
      
  
 
    downloadFile
    
public void downloadFile (String remotePath, 
                File destFile)
    
    
    
  
    
    | Parameters | 
|---|
      
        | remotePath | String | 
      
        | destFile | File | 
    
      
  
 
    downloadFile
    
public File downloadFile (String remoteFilePath)
    
    
    
  Download file from GCS.
 
Right now only support GCS path.
    
    | Parameters | 
|---|
      
        | remoteFilePath | String: gs://bucket/file/path format GCS path. | 
    
    
      
  
 
    isFresh
    
public boolean isFresh (File localFile, 
                String remotePath)
    
    
    
  Check local file's freshness. If local file is the same as remote file, then it's fresh. If
 not, local file is stale. This is mainly used for cache. The default implementation will
 always return true, so if the file is immutable it will never need to check freshness.
    
    | Parameters | 
|---|
      
        | localFile | File: local file. | 
      
        | remotePath | String: remote file path. | 
    
    
      | Returns | 
|---|
      
        | boolean | True if local file is fresh, otherwise false. | 
    
      
  
 
Protected methods
    clearCache
    
protected void clearCache ()
    
    
    
  
 
    downloadFile
    
protected void downloadFile (String bucketName, 
                String remoteFilename, 
                File localFile)
    
    
    
  
    
    | Parameters | 
|---|
      
        | bucketName | String | 
      
        | remoteFilename | String | 
      
        | localFile | File | 
    
      
  
 
    getStorage
    
protected Storage getStorage ( scopes)
    
    
    
  Override the implementation in base to support credential based on TF options.
    
    | Parameters | 
|---|
      
        | scopes | : specific scopes to request credential for. | 
    
    
      | Returns | 
|---|
      
        | Storage | Storageobject of the GCS bucket | 
    
      
  
 
    parseGcsPath
    
protected String[] parseGcsPath (String remotePath)
    
    
    
  
    
    | Parameters | 
|---|
      
        | remotePath | String | 
    
    
      
  
 
 
 
  
  
 
  
    
    
      
    
    
  
       
    
    
  
  
  Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
  Last updated 2025-06-12 UTC.
  
  
  
    
      [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-12 UTC."],[],[]]