GCSFileDownloader

public class GCSFileDownloader
extends GCSCommon implements IFileDownloader

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


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

Summary

Fields

public static final String GCS_APPROX_PREFIX

public static final String GCS_PREFIX

Public constructors

GCSFileDownloader(File jsonKeyFile)
GCSFileDownloader()

Public methods

static File createTempFileForRemote(String remoteFilePath, File rootDir)

Creates a unique file on temporary disk to house downloaded file with given path.

InputStream downloadFile(String bucketName, String filename)

Download a file from a GCS bucket file.

void downloadFile(String remotePath, File destFile)

Alternate form of downloadFile(String), that allows caller to specify the destination file the remote contents should be placed in.

File downloadFile(String remoteFilePath)

Download file from GCS.

boolean isFresh(File localFile, String remotePath)

Check local file's freshness.

Protected methods

void clearCache()

Fields

GCS_APPROX_PREFIX

public static final String GCS_APPROX_PREFIX

GCS_PREFIX

public static final String GCS_PREFIX

Public constructors

GCSFileDownloader

public GCSFileDownloader (File jsonKeyFile)

Parameters
jsonKeyFile File

GCSFileDownloader

public GCSFileDownloader ()

Public methods

createTempFileForRemote

public static File createTempFileForRemote (String remoteFilePath, 
                File rootDir)

Creates a unique file on temporary disk to house downloaded file with given path.

Constructs the file name based on base file name from path

Parameters
remoteFilePath String: the remote path to construct the name from

rootDir File

Returns
File

Throws
BuildRetrievalError

downloadFile

public InputStream downloadFile (String bucketName, 
                String filename)

Download a file from a GCS bucket file.

Parameters
bucketName String: GCS bucket name

filename String: the filename

Returns
InputStream ERROR(/InputStream) with the file content.

downloadFile

public void downloadFile (String remotePath, 
                File destFile)

Alternate form of downloadFile(String), that allows caller to specify the destination file the remote contents should be placed in.

Parameters
remotePath String: the remote path to the file to download, relative to an implementation-specific root.

destFile File: the file to place the downloaded contents into. Should not exist.

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 ()