1.10.2 Bucket操作API的签名和示例
优质
小牛编辑
124浏览
2023-12-01
PUT Bucket
函数签名
/**
* Creates a new fds bucket with the specified name.
*
* @param bucketName The name of the bucket to create
* @throws GalaxyFDSClientException
*/
public void createBucket(String bucketName) throws GalaxyFDSClientException;
示例
fdsClient.createBucket(BUCKET_NAME);
DELETE Bucket
函数签名
/**
* Deletes a fds bucket with the specified name.
*
* @param bucketName The name of the bucket to delete
* @throws GalaxyFDSClientException
*/
public void deleteBucket(String bucketName) throws GalaxyFDSClientException;
示例
fdsClient.deleteBucket(BUCKET_NAME);
HEAD Bucket
函数签名
/**
* Checks if the specified bucket exists.
*
* @param bucketName The name of the bucket to check
* @return The value true if the specified bucket exists, otherwise false
* @throws GalaxyFDSClientException
*/
public boolean doesBucketExist(String bucketName)
throws GalaxyFDSClientException;
示例
boolean exist = fdsClient.doesBucketExist(BUCKET_NAME);
PUT Bucket ACL
函数签名
/**
* Sets the AccessControlList(ACL) of the specified fds bucket.
*
* @param bucketName The name of the bucket whoses acl is being set
* @param acl The new AccessControlList for the specified bucket
* @throws GalaxyFDSClientException
*/
public void setBucketAcl(String bucketName, AccessControlList acl)
throws GalaxyFDSClientException;
示例
AccessControlList acl = new AccessControlList();
Grant grant = new Grant("12346", Permission.READ, GrantType.USER);
acl.addGrant(grant);
fdsClient.setBucketAcl(BUCKET_NAME, acl);
GET Bucket ACL
函数签名
/**
* Gets the AccessControlList(ACL) of the specified fds bucket.
*
* @param bucketName The name of the bucket whose ACL is being retrieved
* @return The AccessControlList for the specified bucket
* @throws GalaxyFDSClientException
*/
public AccessControlList getBucketAcl(String bucketName)
throws GalaxyFDSClientException;
示例
AccessControlList acl = fdsClient.getBucketAcl(BUCKET_NAME);
for (Grant grant : acl.getGrantList()) {
System.out.println("grantee: " + grant.getGranteeId() + ", permission: "
+ grant.getPermission() + ", type: " + grant.getType());
}
List Objects
函数签名
/**
* Returns a list of summary information about the objects in the specified
* fds bucket.
* <p/>
* Because buckets can contain a virtually unlimited number of keys, the
* complete results of a list query can be extremely large. To manage large
* result sets, galaxy fds uses pagination to split them into multiple
* responses. Always check the {@link #FDSObjectListing.isTruncated()} method
* to see if the returned listing is complete or if additional calls are
* needed to get more results. Alternatively, use the
* {@link #listNextBatchOfObjects(FDSObjectListing)} method as an easy way to
* get the next page of object listings.
*
* @param bucketName The name of the bucket to list
* @return A listing of the objects in the specified bucket
* @throws GalaxyFDSClientException
*/
public FDSObjectListing listObjects(String bucketName)
throws GalaxyFDSClientException;
/**
* Returns a list of summary information about the objects in the specified
* fds bucket.
*
* @param bucketName The name of the bucket to list
* @param prefix An optional parameter restricting the response to keys
* beginning with the specified prefix.
* @return A listing of the objects in the specified bucket
* @throws GalaxyFDSClientException
*/
public FDSObjectListing listObjects(String bucketName, String prefix)
throws GalaxyFDSClientException;
/**
* Returns a list of summary information about the objects in the specified
* fds bucket.
*
* @param bucketName The name of the bucket to list
* @param prefix An optional parameter restricting the response to keys
* beginning with the specified prefix.
* @param delimiter delimiter to separate path
* @return A listing of the objects in the specified bucket
* @throws GalaxyFDSClientException
*/
public FDSObjectListing listObjects(String bucketName, String prefix,
String delimiter) throws GalaxyFDSClientException;
/**
* Provides an easy way to continue a truncated object listing and retrieve
* the next page of results.
*
* @param previousObjectListing The previous truncated ObjectListing
* @return The next set of ObjectListing results, beginning immediately after
* the last result in the specified previous ObjectListing.
* @throws GalaxyFDSClientException
*/
public FDSObjectListing listNextBatchOfObjects(
FDSObjectListing previousObjectListing) throws GalaxyFDSClientException;
示例
FDSObjectListing listing = null;
do {
if (listing == null) {
listing = fdsClient.listObjects(bucketName, "", "/");
} else {
listing = fdsClient.listNextBatchOfObjects(listing);
}
if (listing != null) {
List<String> commonPrefixes = listing.getCommonPrefixes();
for (String commonPrefix : commonPrefixes) {
System.out.println(commonPrefix);
}
List<FDSObjectSummary> objectSummaries = listing.getObjectSummaries();
for (FDSObjectSummary objectSummary : objectSummaries) {
System.out.println(objectSummary.getObjectName());
}
}
}
while (listing != null && listing.isTruncated());
Note
更多例子,请参考List Objects REST API