GCSFileDownloaderBase

public class GCSFileDownloaderBase
extends GCSCommon

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


用于从 Google Cloud Storage (GCS) 下载文件的文件下载器。

摘要

常量

String GCS_APPROX_PREFIX

String GCS_PREFIX

字段

protected Boolean mCreateEmptyFile

公共构造函数

GCSFileDownloaderBase()
GCSFileDownloaderBase(Boolean createEmptyFile)

公共方法

static File createTempFileForRemote(String remoteFilePath, File rootDir)

在临时磁盘上创建一个唯一的文件,用于存放具有指定路径的下载文件。

InputStream downloadFile(String bucketName, String filename)

从 GCS 存储分区文件下载文件。

void downloadFile(String remotePath, File destFile)
File downloadFile(String remoteFilePath)
StorageObject getRemoteFileMetaData(String bucketName, String remoteFilename)
boolean isRemoteFolder(String bucketName, String filename)

检查给定的文件名是否为文件夹。

String sanitizeDirectoryName(String name)

受保护的方法

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)

常量

GCS_APPROX_PREFIX

public static final String GCS_APPROX_PREFIX

常量值: "gs:/"

GCS_PREFIX

public static final String GCS_PREFIX

常量值: "gs://"

字段

mCreateEmptyFile

protected Boolean mCreateEmptyFile

公共构造函数

GCSFileDownloaderBase

public GCSFileDownloaderBase ()

GCSFileDownloaderBase

public GCSFileDownloaderBase (Boolean createEmptyFile)

参数
createEmptyFile Boolean

公共方法

createTempFileForRemote

public static File createTempFileForRemote (String remoteFilePath, 
                File rootDir)

在临时磁盘上创建一个唯一的文件,用于存放具有指定路径的下载文件。

根据路径中的基本文件名构造文件名

参数
remoteFilePath String:用于构造名称的远程路径

rootDir File

返回
File

downloadFile

public InputStream downloadFile (String bucketName, 
                String filename)

从 GCS 存储分区文件下载文件。

参数
bucketName String:GCS 存储分区名称

filename String:文件名

返回
InputStream ERROR(/InputStream) 替换为文件内容。

downloadFile

public void downloadFile (String remotePath, 
                File destFile)

参数
remotePath String

destFile File

downloadFile

public File downloadFile (String remoteFilePath)

参数
remoteFilePath String

返回
File

getRemoteFileMetaData

public StorageObject getRemoteFileMetaData (String bucketName, 
                String remoteFilename)

参数
bucketName String

remoteFilename String

返回
StorageObject

isRemoteFolder

public boolean isRemoteFolder (String bucketName, 
                String filename)

检查给定的文件名是否为文件夹。

GCS 中有 2 种类型的文件夹:1. 通过界面明确创建。相应文件夹是一个大小为 0 的文本文件(它是一个对象)。2. 上传文件时,系统会创建其所有父文件夹,但这些文件夹在 GCS 中不存在(不是对象)。此函数适用于这两种情况。但是,我们不应尝试下载大小为 0 的文件夹。

参数
bucketName String:是 GCS 存储分区名称。

filename String:是存储分区的相对路径。

返回
boolean 如果相应文件名是文件夹,则返回 true,否则返回 false。

sanitizeDirectoryName

public String sanitizeDirectoryName (String name)

参数
name String

返回
String

受保护的方法

createTempFile

protected File createTempFile (String remoteFilePath, 
                File rootDir)

参数
remoteFilePath String

rootDir File

返回
File

downloadFile

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

参数
bucketName String

remoteFilename String

localFile File

getStorage

protected Storage getStorage ()

返回
Storage

listRemoteFilesUnderFolder

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

参数
bucketName String

folder String

subFiles

subFolders

parseGcsPath

protected String[] parseGcsPath (String remotePath)

参数
remotePath String

返回
String[]