/** * Creates a {@link Bucket} under the specified project in Cloud Storage or propagates an * exception. */ public void createBucket(String projectId, Bucket bucket) throws IOException { createBucket(projectId, bucket, createBackOff(), Sleeper.DEFAULT); }
/** Returns whether the GCS bucket exists and is accessible. */ public boolean bucketAccessible(GcsPath path) throws IOException { return bucketAccessible(path, createBackOff(), Sleeper.DEFAULT); }
/** Returns the {@link StorageObject} for the given {@link GcsPath}. */ public StorageObject getObject(GcsPath gcsPath) throws IOException { return getObject(gcsPath, createBackOff(), Sleeper.DEFAULT); }
/** * Returns the project number of the project which owns this bucket. If the bucket exists, it must * be accessible otherwise the permissions exception will be propagated. If the bucket does not * exist, an exception will be thrown. */ public long bucketOwner(GcsPath path) throws IOException { return getBucket(path, createBackOff(), Sleeper.DEFAULT).getProjectNumber().longValue(); }
/** Lists {@link Objects} given the {@code bucket}, {@code prefix}, {@code pageToken}. */ public Objects listObjects(String bucket, String prefix, @Nullable String pageToken) throws IOException { // List all objects that start with the prefix (including objects in sub-directories). Storage.Objects.List listObject = storageClient.objects().list(bucket); listObject.setMaxResults(MAX_LIST_ITEMS_PER_CALL); listObject.setPrefix(prefix); if (pageToken != null) { listObject.setPageToken(pageToken); } try { return ResilientOperation.retry( ResilientOperation.getGoogleRequestCallable(listObject), createBackOff(), RetryDeterminer.SOCKET_ERRORS, IOException.class); } catch (Exception e) { throw new IOException( String.format("Unable to match files in bucket %s, prefix %s.", bucket, prefix), e); } }