This class should NOT be used from the scope of a test (i.e., IRemoteTest). This is
deprecated, please use GCSFileDownloader
instead.
Nested classes
class
GCSBucketUtil.GCSFileMetadata
Simple wrapper for file info in GCS.
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 (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)
GCSBucketUtil.GCSFileMetadata
stat (Path bucketPath)
Get the state of the file for the GCS path.
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
getAttempts
public int getAttempts ()
getBotoConfig
public String getBotoConfig ()
getBotoPath
public String getBotoPath ()
getBucketName
public String getBucketName ()
getNoClobber
public boolean getNoClobber ()
getParallel
public boolean getParallel ()
getRecursive
public boolean getRecursive ()
getRetryInterval
public long getRetryInterval ()
getTimeout
public long getTimeout ()
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.
ls
public ls (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
makeBucket
public CommandResult makeBucket (String projectId)
Make the GCS bucket.
Parameters
projectId
String
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.
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
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
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
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
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
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)
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
remove
public CommandResult remove (Path path)
Remove a file or directory from the bucket.
Parameters
path
Path
: Path to remove
remove
public CommandResult remove (String pattern)
Remove a file or directory from the bucket.
Parameters
pattern
String
: File, directory, or pattern to remove.
removeBucket
public CommandResult removeBucket ()
Remove the GCS bucket
setAttempts
public void setAttempts (int attempts)
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)
stat
public GCSBucketUtil.GCSFileMetadata stat (Path bucketPath)
Get the state of the file for the GCS path.
Parameters
bucketPath
Path
: the GCS path
Protected methods
getRunUtil
protected IRunUtil getRunUtil ()
Feedback geben
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 2020-09-08 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Benötigte Informationen nicht gefunden"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Zu umständlich/zu viele Schritte"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Nicht mehr aktuell"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Problem mit der Übersetzung"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Problem mit Beispielen/Code"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Sonstiges"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Leicht verständlich"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Mein Problem wurde gelöst"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Sonstiges"
}]
Haben Sie Feedback für uns?