GCSFileDownloader

public class GCSFileDownloader
extends GCSFileDownloaderBase implements IFileDownloader

java.lang.Object
   ↳ com.android.tradefed.util.gcs.GCSCommon
     ↳ com.android.tradefed.util.gcs.GCSFileDownloaderBase
       ↳ com.android.tradefed.util.GCSFileDownloader


File downloader to download file from google cloud storage (GCS).

Summary

Public constructors

GCSFileDownloader()
GCSFileDownloader(Boolean createEmptyFile)
GCSFileDownloader(File jsonKeyFile)

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

Public methods

createTempFileForRemote

public static File createTempFileForRemote (String remoteFilePath, 
                File rootDir)

Parameters
remoteFilePath String

rootDir File

Returns
File

Throws
BuildRetrievalError

downloadFile

public void downloadFile (String remotePath, 
                File destFile)

Parameters
remotePath String

destFile File

Throws
BuildRetrievalError

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.

Returns
File local file

Throws
com.android.tradefed.build.BuildRetrievalError
BuildRetrievalError

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.

Throws
BuildRetrievalError

Protected methods

clearCache

protected void clearCache ()

downloadFile

protected void downloadFile (String bucketName, 
                String remoteFilename, 
                File localFile)

Parameters
bucketName String

remoteFilename String

localFile File

Throws
BuildRetrievalError

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 Storage object of the GCS bucket

Throws
IOException

parseGcsPath

protected String[] parseGcsPath (String remotePath)

Parameters
remotePath String

Returns
String[]

Throws
BuildRetrievalError