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).

Summary

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()
CommandResult makeBucket(String projectId)

Make the GCS bucket.

CommandResult pull(Path bucketPath)

Download a file or directory from a GCS bucket to the current directory.

CommandResult pull(Path bucketPath, File localFile)

Download a file or directory from a GCS bucket.

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(String pattern, boolean force)

Remove a file or directory from the bucket.

CommandResult remove(Path path, boolean force)

Remove a file or directory from the bucket.

CommandResult remove(Path path)

Remove a file or directory from the bucket.

CommandResult remove(String pattern)

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)

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.

Throws
IOException

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

makeBucket

public CommandResult makeBucket (String projectId)

Make the GCS bucket.

Parameters
projectId String

Returns
CommandResult CommandResult result of the operation.

Throws
IOException

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.

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.

Throws
IOException

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

Throws
IOException

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.

Throws
IOException

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.

Throws
IOException

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.

Throws
IOException

remove

public CommandResult remove (String pattern, 
                boolean force)

Remove a file or directory from the bucket.

Parameters
pattern String: File, directory, or pattern to remove.

force boolean: Whether to ignore failures and continue silently (will not throw)

Returns
CommandResult

Throws
IOException

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

Throws
IOException

remove

public CommandResult remove (Path path)

Remove a file or directory from the bucket.

Parameters
path Path: Path to remove

Returns
CommandResult

Throws
IOException

remove

public CommandResult remove (String pattern)

Remove a file or directory from the bucket.

Parameters
pattern String: File, directory, or pattern to remove.

Returns
CommandResult

Throws
IOException

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

Protected methods

getRunUtil

protected IRunUtil getRunUtil ()

Returns
IRunUtil