Storage.Buckets.Get getBucket = storage.buckets().get(bucketName); getBucket.setProjection("full");
@Override public Bucket get(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_BUCKET); Scope scope = tracer.withSpan(span); try { return storage .buckets() .get(bucket.getName()) .setProjection(DEFAULT_PROJECTION) .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options)) .setFields(Option.FIELDS.getString(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } finally { scope.close(); span.end(); } }
@Override public Bucket get(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_BUCKET); Scope scope = tracer.withSpan(span); try { return storage .buckets() .get(bucket.getName()) .setProjection(DEFAULT_PROJECTION) .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options)) .setFields(Option.FIELDS.getString(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } finally { scope.close(); span.end(); } }
@Override public Bucket get(Bucket bucket, Map<Option, ?> options) { try { return storage.buckets() .get(bucket.getName()) .setProjection(DEFAULT_PROJECTION) .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options)) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { StorageException serviceException = translate(ex); if (serviceException.code() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
/** * Fetches the metadata for the given bucket. * * @param bucketName the name of the bucket to get metadata about. * @return a Bucket containing the bucket's metadata. */ public static Bucket getBucket(String bucketName) throws IOException, GeneralSecurityException { Storage client = StorageFactory.getService(); Storage.Buckets.Get bucketRequest = client.buckets().get(bucketName); // Fetch the full set of the bucket's properties (e.g. include the ACLs in the response) bucketRequest.setProjection("full"); return bucketRequest.execute(); } // [END get_bucket]
public static Bucket get(Storage storage, String bucketName) throws IOException { Storage.Buckets.Get getBucket = storage.buckets().get(bucketName); getBucket.setProjection("full"); // if you are interested in acls. return getBucket.execute(); }