GCSBucketUtil
public
class
GCSBucketUtil
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.util.GCSBucketUtil |
檔案管理員,可從 Google Cloud Storage (GCS) 下載及上傳檔案。
這個類別「不應」從測試範圍 (即 IRemoteTest)。這項政策已淘汰,請改用 GCSFileDownloader。
摘要
巢狀類別 | |
|---|---|
class |
GCSBucketUtil.GCSFileMetadata
GCS 中檔案資訊的簡單包裝函式。 |
公用建構函式 | |
|---|---|
GCSBucketUtil(String bucketName)
|
|
公用方法 | |
|---|---|
CommandResult
|
copy(String source, String dest)
將檔案或目錄複製到值區,或是從值區複製檔案或目錄。 |
int
|
getAttempts()
|
String
|
getBotoConfig()
|
String
|
getBotoPath()
|
String
|
getBucketName()
|
boolean
|
getNoClobber()
|
boolean
|
getParallel()
|
boolean
|
getRecursive()
|
long
|
getRetryInterval()
|
long
|
getTimeout()
|
boolean
|
isFile(String path)
檢查 GCS 檔案是否為檔案 (而非資料夾)。 |
List<String>
|
ls(Path bucketPath)
列出 GCS 路徑下的檔案。 |
CommandResult
|
makeBucket(String projectId)
建立 GCS bucket。 |
String
|
md5Hash(File localFile)
計算本機檔案的 MD5 雜湊。 |
CommandResult
|
pull(Path bucketPath)
從 GCS bucket 下載檔案或目錄至目前目錄。 |
CommandResult
|
pull(Path bucketPath, File localFile)
從 GCS bucket 下載檔案或目錄。 |
String
|
pullContents(Path bucketPath)
從 GCS bucket 下載檔案,並擷取內容。 |
CommandResult
|
push(File localFile)
將本機檔案或目錄上傳至 GCS bucket。 |
CommandResult
|
push(File localFile, Path bucketPath)
將本機檔案或目錄上傳至具有特定路徑的 GCS bucket。 |
CommandResult
|
pushString(String contents, Path bucketPath)
將字串上傳至 GCS bucket。 |
CommandResult
|
remove(String pattern, boolean force)
從 bucket 中移除檔案或目錄。 |
CommandResult
|
remove(Path path, boolean force)
從 bucket 中移除檔案或目錄。 |
CommandResult
|
remove(Path path)
從 bucket 中移除檔案或目錄。 |
CommandResult
|
remove(String pattern)
從 bucket 中移除檔案或目錄。 |
CommandResult
|
removeBucket()
移除 GCS bucket |
void
|
setAttempts(int attempts)
|
void
|
setBotoConfig(String botoConfig)
|
void
|
setBotoPath(String botoPath)
|
void
|
setBucketName(String bucketName)
|
void
|
setNoClobber(boolean noClobber)
|
void
|
setParallel(boolean parallel)
|
void
|
setRecursive(boolean recursive)
|
void
|
setRetryInterval(long retryInterval)
|
void
|
setTimeout(long timeout, TimeUnit unit)
|
void
|
setTimeoutMs(long timeout)
|
GCSBucketUtil.GCSFileMetadata
|
stat(Path bucketPath)
取得 GCS 路徑的檔案狀態。 |
受保護的方法 | |
|---|---|
IRunUtil
|
getRunUtil()
|
公用建構函式
GCSBucketUtil
public GCSBucketUtil (String bucketName)
| 參數 | |
|---|---|
bucketName |
String |
公用方法
複製
public CommandResult copy (String source, String dest)
將檔案或目錄複製到值區,或是從值區複製檔案或目錄。
| 參數 | |
|---|---|
source |
String:來源檔案或模式 |
dest |
String:目的地檔案或模式 |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
IOException |
|
getAttempts
public int getAttempts ()
| 傳回 | |
|---|---|
int |
|
getBotoConfig
public String getBotoConfig ()
| 傳回 | |
|---|---|
String |
|
getBotoPath
public String getBotoPath ()
| 傳回 | |
|---|---|
String |
|
getBucketName
public String getBucketName ()
| 傳回 | |
|---|---|
String |
|
getNoClobber
public boolean getNoClobber ()
| 傳回 | |
|---|---|
boolean |
|
getParallel
public boolean getParallel ()
| 傳回 | |
|---|---|
boolean |
|
getRecursive
public boolean getRecursive ()
| 傳回 | |
|---|---|
boolean |
|
getRetryInterval
public long getRetryInterval ()
| 傳回 | |
|---|---|
long |
|
getTimeout
public long getTimeout ()
| 傳回 | |
|---|---|
long |
|
isFile
public boolean isFile (String path)
檢查 GCS 檔案是否為檔案 (而非資料夾)。
如果檔案名稱結尾為「/」,則為資料夾。如果檔案名稱結尾為「/」,則 gsutil ls gs://filename 應會傳回 gs://filename。如果資料夾中有檔案,gsutil ls gs://folder name 應會傳回資料夾中的檔案。如果資料夾中沒有任何檔案,則會傳回 gs://folder/。
| 參數 | |
|---|---|
path |
String:相對於 bucket 的路徑。 |
| 傳回 | |
|---|---|
boolean |
是檔案還是不是檔案。 |
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|
ls
public List<String> ls (Path bucketPath)
列出 GCS 路徑下的檔案。
| 參數 | |
|---|---|
bucketPath |
Path:GCS 路徑 |
| 傳回 | |
|---|---|
List<String> |
GCS 路徑下的檔案清單 String |
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|
makeBucket
public CommandResult makeBucket (String projectId)
建立 GCS bucket。
| 參數 | |
|---|---|
projectId |
String |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|
md5Hash
public String md5Hash (File localFile)
計算本機檔案的 MD5 雜湊。
| 參數 | |
|---|---|
localFile |
File:本機檔案 |
| 傳回 | |
|---|---|
String |
本機檔案的 MD5 雜湊。 |
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|
提取
public CommandResult pull (Path bucketPath)
從 GCS bucket 下載檔案或目錄至目前目錄。
| 參數 | |
|---|---|
bucketPath |
Path:GCS bucket 中的檔案路徑 |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
IOException |
|
提取
public CommandResult pull (Path bucketPath, File localFile)
從 GCS bucket 下載檔案或目錄。
| 參數 | |
|---|---|
bucketPath |
Path:GCS bucket 中的檔案路徑 |
localFile |
File:本機目的地路徑 |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
IOException |
|
pullContents
public String pullContents (Path bucketPath)
從 GCS bucket 下載檔案,並擷取內容。
| 參數 | |
|---|---|
bucketPath |
Path:GCS bucket 中的檔案路徑 |
| 傳回 | |
|---|---|
String |
檔案的字串內容 |
| 擲回 | |
|---|---|
IOException |
|
推送
public CommandResult push (File localFile)
將本機檔案或目錄上傳至 GCS bucket。
| 參數 | |
|---|---|
localFile |
File:本機檔案或目錄 |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
IOException |
|
推送
public CommandResult push (File localFile, Path bucketPath)
將本機檔案或目錄上傳至具有特定路徑的 GCS bucket。
| 參數 | |
|---|---|
localFile |
File:本機檔案或目錄 |
bucketPath |
Path:GCS bucket 中的檔案路徑 |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
IOException |
|
pushString
public CommandResult pushString (String contents, Path bucketPath)
將字串上傳至 GCS bucket。
| 參數 | |
|---|---|
contents |
String:檔案內容 (字串) |
bucketPath |
Path:GCS bucket 中的檔案路徑 |
| 傳回 | |
|---|---|
CommandResult |
CommandResult 作業結果。 |
| 擲回 | |
|---|---|
IOException |
|
移除
public CommandResult remove (String pattern, boolean force)
從 bucket 中移除檔案或目錄。
| 參數 | |
|---|---|
pattern |
String:要移除的檔案、目錄或模式。 |
force |
boolean:是否要忽略失敗並繼續執行 (不會擲回例外狀況) |
| 傳回 | |
|---|---|
CommandResult |
|
| 擲回 | |
|---|---|
IOException |
|
移除
public CommandResult remove (Path path, boolean force)
從 bucket 中移除檔案或目錄。
| 參數 | |
|---|---|
path |
Path:要移除的路徑 |
force |
boolean:檔案不存在時是否失敗 |
| 傳回 | |
|---|---|
CommandResult |
|
| 擲回 | |
|---|---|
IOException |
|
移除
public CommandResult remove (Path path)
從 bucket 中移除檔案或目錄。
| 參數 | |
|---|---|
path |
Path:要移除的路徑 |
| 傳回 | |
|---|---|
CommandResult |
|
| 擲回 | |
|---|---|
IOException |
|
移除
public CommandResult remove (String pattern)
從 bucket 中移除檔案或目錄。
| 參數 | |
|---|---|
pattern |
String:要移除的檔案、目錄或模式。 |
| 傳回 | |
|---|---|
CommandResult |
|
| 擲回 | |
|---|---|
IOException |
|
removeBucket
public CommandResult removeBucket ()
移除 GCS bucket
| 傳回 | |
|---|---|
CommandResult |
|
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|
setAttempts
public void setAttempts (int attempts)
| 參數 | |
|---|---|
attempts |
int |
setBotoConfig
public void setBotoConfig (String botoConfig)
| 參數 | |
|---|---|
botoConfig |
String |
setBotoPath
public void setBotoPath (String botoPath)
| 參數 | |
|---|---|
botoPath |
String |
setBucketName
public void setBucketName (String bucketName)
| 參數 | |
|---|---|
bucketName |
String |
setNoClobber
public void setNoClobber (boolean noClobber)
| 參數 | |
|---|---|
noClobber |
boolean |
setParallel
public void setParallel (boolean parallel)
| 參數 | |
|---|---|
parallel |
boolean |
setRecursive
public void setRecursive (boolean recursive)
| 參數 | |
|---|---|
recursive |
boolean |
setRetryInterval
public void setRetryInterval (long retryInterval)
| 參數 | |
|---|---|
retryInterval |
long |
setTimeout
public void setTimeout (long timeout,
TimeUnit unit)| 參數 | |
|---|---|
timeout |
long |
unit |
TimeUnit |
setTimeoutMs
public void setTimeoutMs (long timeout)
| 參數 | |
|---|---|
timeout |
long |
stat
public GCSBucketUtil.GCSFileMetadata stat (Path bucketPath)
取得 GCS 路徑的檔案狀態。
| 參數 | |
|---|---|
bucketPath |
Path:GCS 路徑 |
| 傳回 | |
|---|---|
GCSBucketUtil.GCSFileMetadata |
GCSFileMetadata,適用於 GCS 路徑 |
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|