GCSBucketUtil
public
class
GCSBucketUtil
extends Object
java.lang.Object | |
↳ | com.android.tradefed.util.GCSBucketUtil |
File manager to download and upload files from Google Cloud Storage (GCS).
This class should NOT be used from the scope of a test (i.e., IRemoteTest). This is
deprecated, please use GCSFileDownloader
instead.
Summary
Nested classes | |
---|---|
class |
GCSBucketUtil.GCSFileMetadata
Simple wrapper for file info in GCS. |
Public constructors | |
---|---|
GCSBucketUtil(String bucketName)
|
Public methods | |
---|---|
CommandResult
|
copy(String source, String dest)
Copy a file or directory to or from the bucket. |
int
|
getAttempts()
|
String
|
getBotoConfig()
|
String
|
getBotoPath()
|
String
|
getBucketName()
|
boolean
|
getNoClobber()
|
boolean
|
getParallel()
|
boolean
|
getRecursive()
|
long
|
getRetryInterval()
|
long
|
getTimeout()
|
boolean
|
isFile(String path)
Check a GCS file is a file or not a file (a folder). |
|
ls(Path bucketPath)
List files under a GCS path. |
CommandResult
|
makeBucket(String projectId)
Make the GCS bucket. |
String
|
md5Hash(File localFile)
Calculate the md5 hash for the local file. |
CommandResult
|
pull(Path bucketPath, File localFile)
Download a file or directory from a GCS bucket. |
CommandResult
|
pull(Path bucketPath)
Download a file or directory from a GCS bucket to the current directory. |
String
|
pullContents(Path bucketPath)
Download a file from a GCS bucket, and extract its contents. |
CommandResult
|
push(File localFile)
Upload a local file or directory to a GCS bucket. |
CommandResult
|
push(File localFile, Path bucketPath)
Upload a local file or directory to a GCS bucket with a specific path. |
CommandResult
|
pushString(String contents, Path bucketPath)
Upload a String to a GCS bucket. |
CommandResult
|
remove(Path path)
Remove a file or directory from the bucket. |
CommandResult
|
remove(Path path, boolean force)
Remove a file or directory from the bucket. |
CommandResult
|
removeBucket()
Remove the 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)
Get the state of the file for the GCS path. |
Protected methods | |
---|---|
IRunUtil
|
getRunUtil()
|
Public constructors
GCSBucketUtil
public GCSBucketUtil (String bucketName)
Parameters | |
---|---|
bucketName |
String |
Public methods
copy
public CommandResult copy (String source, String dest)
Copy a file or directory to or from the bucket.
Parameters | |
---|---|
source |
String : Source file or pattern |
dest |
String : Destination file or pattern |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
getAttempts
public int getAttempts ()
Returns | |
---|---|
int |
getBotoConfig
public String getBotoConfig ()
Returns | |
---|---|
String |
getBotoPath
public String getBotoPath ()
Returns | |
---|---|
String |
getBucketName
public String getBucketName ()
Returns | |
---|---|
String |
getNoClobber
public boolean getNoClobber ()
Returns | |
---|---|
boolean |
getParallel
public boolean getParallel ()
Returns | |
---|---|
boolean |
getRecursive
public boolean getRecursive ()
Returns | |
---|---|
boolean |
getRetryInterval
public long getRetryInterval ()
Returns | |
---|---|
long |
getTimeout
public long getTimeout ()
Returns | |
---|---|
long |
isFile
public boolean isFile (String path)
Check a GCS file is a file or not a file (a folder).
If the filename ends with '/', then it's a folder. gsutil ls gs://filename should return the gs://filename if it's a file. gsutil ls gs://folder name should return the files in the folder if there are files in the folder. And it will return gs://folder/ if there is no files in the folder.
Parameters | |
---|---|
path |
String : the path relative to bucket.. |
Returns | |
---|---|
boolean |
it's a file or not a file. |
Throws | |
---|---|
|
IOException |
ls
publicls (Path bucketPath)
List files under a GCS path.
Parameters | |
---|---|
bucketPath |
Path : the GCS path |
Returns | |
---|---|
|
a list of String s that are files under the GCS path |
Throws | |
---|---|
|
IOException |
makeBucket
public CommandResult makeBucket (String projectId)
Make the GCS bucket.
Parameters | |
---|---|
projectId |
String |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
Throws | |
---|---|
|
IOException |
md5Hash
public String md5Hash (File localFile)
Calculate the md5 hash for the local file.
Parameters | |
---|---|
localFile |
File : a local file |
Returns | |
---|---|
String |
the md5 hash for the local file. |
Throws | |
---|---|
|
IOException |
pull
public CommandResult pull (Path bucketPath, File localFile)
Download a file or directory from a GCS bucket.
Parameters | |
---|---|
bucketPath |
Path : File path in the GCS bucket |
localFile |
File : Local destination path |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
pull
public CommandResult pull (Path bucketPath)
Download a file or directory from a GCS bucket to the current directory.
Parameters | |
---|---|
bucketPath |
Path : File path in the GCS bucket |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
pullContents
public String pullContents (Path bucketPath)
Download a file from a GCS bucket, and extract its contents.
Parameters | |
---|---|
bucketPath |
Path : File path in the GCS bucket |
Returns | |
---|---|
String |
String contents of the file |
push
public CommandResult push (File localFile)
Upload a local file or directory to a GCS bucket.
Parameters | |
---|---|
localFile |
File : Local file or directory |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
push
public CommandResult push (File localFile, Path bucketPath)
Upload a local file or directory to a GCS bucket with a specific path.
Parameters | |
---|---|
localFile |
File : Local file or directory |
bucketPath |
Path : File path in the GCS bucket |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
pushString
public CommandResult pushString (String contents, Path bucketPath)
Upload a String to a GCS bucket.
Parameters | |
---|---|
contents |
String : File contents, as a string |
bucketPath |
Path : File path in the GCS bucket |
Returns | |
---|---|
CommandResult |
CommandResult result of the operation. |
remove
public CommandResult remove (Path path)
Remove a file or directory from the bucket.
Parameters | |
---|---|
path |
Path : Path to remove |
Returns | |
---|---|
CommandResult |
remove
public CommandResult remove (Path path, boolean force)
Remove a file or directory from the bucket.
Parameters | |
---|---|
path |
Path : Path to remove |
force |
boolean : Whether to fail if the file does not exist |
Returns | |
---|---|
CommandResult |
removeBucket
public CommandResult removeBucket ()
Remove the GCS bucket
Returns | |
---|---|
CommandResult |
Throws | |
---|---|
|
IOException |
setAttempts
public void setAttempts (int attempts)
Parameters | |
---|---|
attempts |
int |
setBotoConfig
public void setBotoConfig (String botoConfig)
Parameters | |
---|---|
botoConfig |
String |
setBotoPath
public void setBotoPath (String botoPath)
Parameters | |
---|---|
botoPath |
String |
setBucketName
public void setBucketName (String bucketName)
Parameters | |
---|---|
bucketName |
String |
setNoClobber
public void setNoClobber (boolean noClobber)
Parameters | |
---|---|
noClobber |
boolean |
setParallel
public void setParallel (boolean parallel)
Parameters | |
---|---|
parallel |
boolean |
setRecursive
public void setRecursive (boolean recursive)
Parameters | |
---|---|
recursive |
boolean |
setRetryInterval
public void setRetryInterval (long retryInterval)
Parameters | |
---|---|
retryInterval |
long |
setTimeout
public void setTimeout (long timeout, TimeUnit unit)
Parameters | |
---|---|
timeout |
long |
unit |
TimeUnit |
setTimeoutMs
public void setTimeoutMs (long timeout)
Parameters | |
---|---|
timeout |
long |
stat
public GCSBucketUtil.GCSFileMetadata stat (Path bucketPath)
Get the state of the file for the GCS path.
Parameters | |
---|---|
bucketPath |
Path : the GCS path |
Returns | |
---|---|
GCSBucketUtil.GCSFileMetadata |
GCSFileMetadata for the GCS path |
Throws | |
---|---|
|
IOException |
Protected methods
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-10-08 UTC.