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 檔案是否為檔案或資料夾。  | 
  
        
        
        
        
        
        
     | 
  
    
      
      ls(Path bucketPath)
      
      
        列出 GCS 路徑下的檔案。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      makeBucket(String projectId)
      
      
        建立 GCS 值區。  | 
  
        
        
        
        
        
        String
     | 
  
    
      
      md5Hash(File localFile)
      
      
        計算本機檔案的 MD5 雜湊。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      pull(Path bucketPath, File localFile)
      
      
        從 GCS 值區下載檔案或目錄。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      pull(Path bucketPath)
      
      
        從 GCS 值區下載檔案或目錄至目前目錄。  | 
  
        
        
        
        
        
        String
     | 
  
    
      
      pullContents(Path bucketPath)
      
      
        從 GCS 值區下載檔案,並擷取其內容。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      push(File localFile)
      
      
        將本機檔案或目錄上傳至 GCS 值區。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      push(File localFile, Path bucketPath)
      
      
        將本機檔案或目錄上傳至具有特定路徑的 GCS 值區。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      pushString(String contents, Path bucketPath)
      
      
        將字串上傳至 GCS 值區。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      remove(Path path)
      
      
        從儲存桶中移除檔案或目錄。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      remove(Path path, boolean force)
      
      
        從儲存桶中移除檔案或目錄。  | 
  
        
        
        
        
        
        CommandResult
     | 
  
    
      
      removeBucket()
      
      
        移除 GCS 值區  | 
  
        
        
        
        
        
        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 結果。 | 
      
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:相對於值區的路徑。 | 
      
| 傳回 | |
|---|---|
boolean | 
        是檔案或非檔案。 | 
| 擲回 | |
|---|---|
 | 
          IOException | 
ls
publicls (Path bucketPath) 
列出 GCS 路徑下的檔案。
| 參數 | |
|---|---|
bucketPath | 
        
          Path:GCS 路徑 | 
      
| 傳回 | |
|---|---|
 | 
        GCS 路徑下檔案的 String 清單 | 
      
| 擲回 | |
|---|---|
 | 
          IOException | 
makeBucket
public CommandResult makeBucket (String projectId)
建立 GCS 值區。
| 參數 | |
|---|---|
projectId | 
        
          String  | 
      
| 傳回 | |
|---|---|
CommandResult | 
        作業的 CommandResult 結果。 | 
      
| 擲回 | |
|---|---|
 | 
          IOException | 
md5Hash
public String md5Hash (File localFile)
計算本機檔案的 MD5 雜湊。
| 參數 | |
|---|---|
localFile | 
        
          File:本機檔案 | 
      
| 傳回 | |
|---|---|
String | 
        本機檔案的 MD5 雜湊。 | 
| 擲回 | |
|---|---|
 | 
          IOException | 
提取
public CommandResult pull (Path bucketPath, File localFile)
從 GCS 值區下載檔案或目錄。
| 參數 | |
|---|---|
bucketPath | 
        
          Path:GCS 值區中的檔案路徑 | 
      
localFile | 
        
          File:本機目的地路徑 | 
      
| 傳回 | |
|---|---|
CommandResult | 
        作業的 CommandResult 結果。 | 
      
提取
public CommandResult pull (Path bucketPath)
將檔案或目錄從 GCS 值區下載到目前的目錄。
| 參數 | |
|---|---|
bucketPath | 
        
          Path:GCS 值區中的檔案路徑 | 
      
| 傳回 | |
|---|---|
CommandResult | 
        作業的 CommandResult 結果。 | 
      
pullContents
public String pullContents (Path bucketPath)
從 GCS 值區下載檔案,並擷取其內容。
| 參數 | |
|---|---|
bucketPath | 
        
          Path:GCS 值區中的檔案路徑 | 
      
| 傳回 | |
|---|---|
String | 
        檔案的字串內容 | 
推播
public CommandResult push (File localFile)
將本機檔案或目錄上傳至 GCS 值區。
| 參數 | |
|---|---|
localFile | 
        
          File:本機檔案或目錄 | 
      
| 傳回 | |
|---|---|
CommandResult | 
        作業的 CommandResult 結果。 | 
      
推播
public CommandResult push (File localFile, Path bucketPath)
將本機檔案或目錄上傳至特定路徑的 GCS 值區。
| 參數 | |
|---|---|
localFile | 
        
          File:本機檔案或目錄 | 
      
bucketPath | 
        
          Path:GCS 值區中的檔案路徑 | 
      
| 傳回 | |
|---|---|
CommandResult | 
        作業的 CommandResult 結果。 | 
      
pushString
public CommandResult pushString (String contents, Path bucketPath)
將字串上傳至 GCS 值區。
| 參數 | |
|---|---|
contents | 
        
          String:檔案內容,以字串表示 | 
      
bucketPath | 
        
          Path:GCS 值區中的檔案路徑 | 
      
| 傳回 | |
|---|---|
CommandResult | 
        作業的 CommandResult 結果。 | 
      
移除
public CommandResult remove (Path path, boolean force)
從值區中移除檔案或目錄。
| 參數 | |
|---|---|
path | 
        
          Path:要移除的路徑 | 
      
force | 
        
          boolean:如果檔案不存在,是否要失敗 | 
      
| 傳回 | |
|---|---|
CommandResult | 
        |
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 路徑 | 
      
| 擲回 | |
|---|---|
 | 
          IOException |