GCSFileDownloaderBase

public class GCSFileDownloaderBase
extends GCSCommon

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


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

protected Boolean mCreateEmptyFile

Public constructors

GCSFileDownloaderBase()
GCSFileDownloaderBase(Boolean createEmptyFile)

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)
File downloadFile(String remoteFilePath)
StorageObject getRemoteFileMetaData(String bucketName, String remoteFilename)
boolean isRemoteFolder(String bucketName, String filename)

Check given filename is a folder or not.

String sanitizeDirectoryName(String name)

Protected methods

File createTempFile(String remoteFilePath, File rootDir)
void downloadFile(String bucketName, String remoteFilename, File localFile)
Storage getStorage()
void listRemoteFilesUnderFolder(String bucketName, String folder, subFiles, subFolders)
String[] parseGcsPath(String remotePath)

Fields

GCS_APPROX_PREFIX

public static final String GCS_APPROX_PREFIX

GCS_PREFIX

public static final String GCS_PREFIX

mCreateEmptyFile

protected Boolean mCreateEmptyFile

Public constructors

GCSFileDownloaderBase

public GCSFileDownloaderBase ()

GCSFileDownloaderBase

public GCSFileDownloaderBase (Boolean createEmptyFile)

Parameters
createEmptyFile Boolean

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

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)

Parameters
remotePath String

destFile File

downloadFile

public File downloadFile (String remoteFilePath)

Parameters
remoteFilePath String

Returns
File

getRemoteFileMetaData

public StorageObject getRemoteFileMetaData (String bucketName, 
                String remoteFilename)

Parameters
bucketName String

remoteFilename String

Returns
StorageObject

isRemoteFolder

public boolean isRemoteFolder (String bucketName, 
                String filename)

Check given filename is a folder or not.

There 2 types of folders in gcs: 1. Created explicitly from UI. The folder is a size 0 text file (it's an object). 2. When upload a file, all its parent folders will be created, but these folders doesn't exist (not objects) in gcs. This function work for both cases. But we should not try to download the size 0 folders.

Parameters
bucketName String: is the gcs bucket name.

filename String: is the relative path to the bucket.

Returns
boolean true if the filename is a folder, otherwise false.

sanitizeDirectoryName

public String sanitizeDirectoryName (String name)

Parameters
name String

Returns
String

Protected methods

createTempFile

protected File createTempFile (String remoteFilePath, 
                File rootDir)

Parameters
remoteFilePath String

rootDir File

Returns
File

downloadFile

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

Parameters
bucketName String

remoteFilename String

localFile File

getStorage

protected Storage getStorage ()

Returns
Storage

listRemoteFilesUnderFolder

protected void listRemoteFilesUnderFolder (String bucketName, 
                String folder, 
                 subFiles, 
                 subFolders)

Parameters
bucketName String

folder String

subFiles

subFolders

parseGcsPath

protected String[] parseGcsPath (String remotePath)

Parameters
remotePath String

Returns
String[]