Lists object information in given bucket.

@param bucketName Bucket name.

@return an iterator of Result Items.

* @throws XmlPullParserException      upon parsing response xml
339618
public Iterable<Result<Item>> listObjects(final String bucketName) throws XmlPullParserException {
    return listObjects(bucketName, null);
  }
242119
private Iterable<Result<Part>> listObjectParts(final String bucketName, final String objectName,
                                                 final String uploadId) {
    return new Iterable<Result<Part>>() {
      @Override
      public Iterator<Result<Part>> iterator() {
        return new Iterator<Result<Part>>() {
          private int nextPartNumberMarker;
          private ListPartsResult listPartsResult;
          private Result<Part> error;
          private Iterator<Part> partIterator;
          private boolean completed = false;

          private synchronized void populate() {
            this.listPartsResult = null;
            this.partIterator = null;

            try {
              this.listPartsResult = listObjectParts(bucketName, objectName, uploadId, nextPartNumberMarker);
            } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException
                     | InvalidKeyException | NoResponseException | XmlPullParserException | ErrorResponseException
                     | InternalException e) {
              this.error = new Result<>(null, e);
            } finally {
              if (this.listPartsResult != null) {
                this.partIterator = this.listPartsResult.partList().iterator();
              } else {
                this.partIterator = new LinkedList<Part>().iterator();
              }
            }
          }

          @Override
          public boolean hasNext() {
            if (this.completed) {
              return false;
            }

            if (this.error == null && this.partIterator == null) {
              populate();
            }

            if (this.error == null && !this.partIterator.hasNext() && this.listPartsResult.isTruncated()) {
              this.nextPartNumberMarker = this.listPartsResult.nextPartNumberMarker();
              populate();
            }

            if (this.error != null) {
              return true;
            }

            if (this.partIterator.hasNext()) {
              return true;
            }

            this.completed = true;
            return false;
          }

          @Override
          public Result<Part> next() {
            if (this.completed) {
              throw new NoSuchElementException();
            }

            if (this.error == null && this.partIterator == null) {
              populate();
            }

            if (this.error == null && !this.partIterator.hasNext() && this.listPartsResult.isTruncated()) {
              this.nextPartNumberMarker = this.listPartsResult.nextPartNumberMarker();
              populate();
            }

            if (this.error != null) {
              this.completed = true;
              return this.error;
            }

            if (this.partIterator.hasNext()) {
              return new Result<>(this.partIterator.next(), null);
            }

            this.completed = true;
            throw new NoSuchElementException();
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException();
          }
        };
      }
    };
  }
183918
protected List<StreamingDistributionSummary> getAllExistingDistributions(String bucketName) {

        List<StreamingDistributionSummary> distListForBucket = new ArrayList<>();

        StreamingDistributionList distList =
            cfClient.listStreamingDistributions(new ListStreamingDistributionsRequest())
                    .getStreamingDistributionList();

        List<StreamingDistributionSummary> streamingDistList = distList.getItems();
        while (distList.isTruncated()) {
            distList = cfClient.listStreamingDistributions(
                new ListStreamingDistributionsRequest().withMarker(distList.getNextMarker()))
                               .getStreamingDistributionList();
            streamingDistList.addAll(distList.getItems());
        }

        for (StreamingDistributionSummary distSummary : streamingDistList) {
            if (isDistFromBucket(bucketName, distSummary)) {
                distListForBucket.add(distSummary);
            }
        }

        return distListForBucket;
    }
357448
public Bucket enableBucketPolicyOnly(String bucketName) throws StorageException {
    // [START storage_enable_bucket_policy_only]
    // Instantiate a Google Cloud Storage client
    Storage storage = StorageOptions.getDefaultInstance().getService();

    // The name of a bucket, e.g. "my-bucket"
    // String bucketName = "my-bucket";

    BucketInfo.IamConfiguration iamConfiguration =
        BucketInfo.IamConfiguration.newBuilder().setIsBucketPolicyOnlyEnabled(true).build();
    Bucket bucket =
        storage.update(
            BucketInfo.newBuilder(bucketName).setIamConfiguration(iamConfiguration).build());

    System.out.println("Bucket Policy Only was enabled for " + bucketName);
    // [END storage_enable_bucket_policy_only]
    return bucket;
  }
1224800
public List<Acl> listDefaultBucketAcls(String bucketName) {
    // [START listDefaultBucketAcls]
    List<Acl> acls = storage.listDefaultAcls(bucketName);
    for (Acl acl : acls) {
      // do something with ACL entry
    }
    // [END listDefaultBucketAcls]
    return acls;
  }
835410
@Override
  public List<GoogleCloudStorageItemInfo> listObjectInfo(
      String bucketName, String objectNamePrefix, String delimiter) throws IOException {
    return listObjectInfo(bucketName, objectNamePrefix, delimiter, MAX_RESULTS_UNLIMITED);
  }
976090
def list(self, prefix='', delimiter=None):
        """"""
        return self.service._list(
            bucket=self.name, prefix=prefix, delimiter=delimiter, objects=True
        )
33215
public Iterable<String> listStashTableNames()
            throws StashNotAvailableException {
        return Iterables.transform(listStashTables(), new Function<StashTable, String>() {
            @Override
            public String apply(StashTable stashTable) {
                return stashTable.getTableName();
            }
        });
    }
822981
public List<String> keysForBucket(String bucket) {
        AmazonS3 s3 = getClient();
        List<String> ret = new ArrayList<>();
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket);
        ObjectListing objectListing;

        do {
            objectListing = s3.listObjects(listObjectsRequest);
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                ret.add(objectSummary.getKey());
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());

        return ret;
    }
1137213
def _storage_list(args, _):
  
  target = args['object'] if args['object'] else args['bucket']
  project = args['project']
  if target is None:
    return _storage_list_buckets(project, '*')  # List all buckets.

  bucket_name, key = datalab.storage._bucket.parse_name(target)
  if bucket_name is None:
    raise Exception('Cannot list %s; not a valid bucket name' % target)

  if key or not re.search('\?|\*|\[', target):
    # List the contents of the bucket
    if not key:
      key = '*'
    if project:
      # Only list if the bucket is in the project
      for bucket in datalab.storage.Buckets(project_id=project):
        if bucket.name == bucket_name:
          break
      else:
        raise Exception('%s does not exist in project %s' % (target, project))
    else:
      bucket = datalab.storage.Bucket(bucket_name)

    if bucket.exists():
      return _storage_list_keys(bucket, key)
    else:
      raise Exception('Bucket %s does not exist' % target)

  else:
    # Treat the bucket name as a pattern and show matches. We don't use bucket_name as that
    # can strip off wildchars and so we need to strip off gs:// here.
    return _storage_list_buckets(project, target[5:])
789633
public List<String> buckets() {
        List<String> ret = new ArrayList<>();
        AmazonS3 s3 = getClient();
        List<Bucket> buckets = s3.listBuckets();
        for (Bucket b : buckets)
            ret.add(b.getName());
        return ret;
    }

    /**
     * Iterate over individual buckets.
     * Returns input streams to each object.
     * It is your responsibility to close the input streams
     * @param bucket the bucket to iterate over
     * @return an iterator over the objects in an s3 bucket
     */
    public Iterator<InputStream> iterateBucket(String bucket) {
        return new BucketIterator(bucket, this);
    }

    /**
     * Iterator style one list at a time
     * @param list the list to get the next batch for
     * @return the next batch of objects or null if
     * none are left
     */
    public ObjectListing nextList(ObjectListing list) {
        AmazonS3 s3 = getClient();
        if (list.isTruncated())
            return s3.listNextBatchOfObjects(list);
        return null;
    }

    /**
     * Simple way of retrieving the listings for a bucket
     * @param bucket the bucket to retrieve listings for
     * @return the object listing for this bucket
     */
    public ObjectListing listObjects(String bucket) {
        AmazonS3 s3 = getClient();
        ObjectListing list = s3.listObjects(bucket);
        return list;
    }

    /**
     * Paginates through a bucket's keys invoking the listener 
     * at each key
     * @param bucket the bucket to iterate
     * @param listener the listener
     */
    public void paginate(String bucket, BucketKeyListener listener) {
        AmazonS3 s3 = getClient();
        ObjectListing list = s3.listObjects(bucket);
        for (S3ObjectSummary summary : list.getObjectSummaries()) {
            if (listener != null)
                listener.onKey(s3, bucket, summary.getKey());
        }

        while (list.isTruncated()) {
            list = s3.listNextBatchOfObjects(list);
            for (S3ObjectSummary summary : list.getObjectSummaries()) {
                if (listener != null)
                    listener.onKey(s3, bucket, summary.getKey());
            }
        }


    }


    /**
     * Returns an input stream for the given bucket and key
     * @param bucket the bucket to retrieve from
     * @param key the key of the objec  t
     * @return an input stream to the object
     */
    public InputStream objectForKey(String bucket, String key) {
        AmazonS3 s3 = getClient();
        S3Object obj = s3.getObject(bucket, key);
        InputStream is = obj.getObjectContent();
        return is;
    }


    public void download(String bucket, String key, File to) throws IOException {
        AmazonS3 s3 = getClient();
        S3Object obj = s3.getObject(bucket, key);
        InputStream is = obj.getObjectContent();
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(to));
        IOUtils.copy(is, bos);
        bos.close();
        is.close();
        obj.close();
    }

    public void download(String bucket, String key, OutputStream to) throws IOException {
        AmazonS3 s3 = getClient();
        S3Object obj = s3.getObject(bucket, key);
        InputStream is = obj.getObjectContent();
        BufferedOutputStream bos = new BufferedOutputStream(to);

        IOUtils.copy(is, bos);
        bos.close();
        is.close();
        obj.close();
    }

    public MultipleFileDownload downloadFolder(String bucketName, String keyPrefix, File folderPath) {
        TransferManager transfer = new TransferManager(getClient());
        return transfer.downloadDirectory(bucketName, keyPrefix, folderPath);
    }


}
1189080
protected static String getBucketARN(String bucketName) throws IllegalArgumentException {
        return new StringBuilder().append(S3_ARN_PREFIX).append(bucketName).toString();
    }
882441
@Override
  public List<GoogleCloudStorageItemInfo> listObjectInfo(
      String bucketName, String objectNamePrefix, String delimiter, long maxResults)
      throws IOException {
    logger.atFine().log(
        "listObjectInfo(%s, %s, %s, %s)", bucketName, objectNamePrefix, delimiter, maxResults);

    // Helper will handle going through pages of list results and accumulating them.
    List<StorageObject> listedObjects = new ArrayList<>();
    List<String> listedPrefixes = new ArrayList<>();
    listStorageObjectsAndPrefixes(
        bucketName,
        objectNamePrefix,
        delimiter,
        /* includeTrailingDelimiter= */ true,
        maxResults,
        listedObjects,
        listedPrefixes);

    // For the listedObjects, we simply parse each item into a GoogleCloudStorageItemInfo without
    // further work.
    List<GoogleCloudStorageItemInfo> objectInfos = new ArrayList<>(listedObjects.size());
    for (StorageObject obj : listedObjects) {
      objectInfos.add(
          createItemInfoForStorageObject(new StorageResourceId(bucketName, obj.getName()), obj));
    }

    if (listedPrefixes.isEmpty()) {
      return objectInfos;
    }

    handlePrefixes(bucketName, listedPrefixes, objectInfos);

    return objectInfos;
  }
718226
private void bucket(WebContext ctx, String bucketName) {
        Bucket bucket = storage.getBucket(bucketName);

        if (!objectCheckAuth(ctx, bucket)) {
            return;
        }

        HttpMethod method = ctx.getRequest().method();

        if (HEAD == method) {
            if (bucket.exists()) {
                signalObjectSuccess(ctx);
                ctx.respondWith().status(HttpResponseStatus.OK);
            } else {
                signalObjectError(ctx, HttpResponseStatus.NOT_FOUND, ERROR_BUCKET_DOES_NOT_EXIST);
            }
        } else if (GET == method) {
            if (bucket.exists()) {
                listObjects(ctx, bucket);
            } else {
                signalObjectError(ctx, HttpResponseStatus.NOT_FOUND, ERROR_BUCKET_DOES_NOT_EXIST);
            }
        } else if (DELETE == method) {
            bucket.delete();
            signalObjectSuccess(ctx);
            ctx.respondWith().status(HttpResponseStatus.OK);
        } else if (PUT == method) {
            bucket.create();
            signalObjectSuccess(ctx);
            ctx.respondWith().status(HttpResponseStatus.OK);
        } else {
            throw new IllegalArgumentException(ctx.getRequest().method().name());
        }
    }
1115924
@Override
  public List<GoogleCloudStorageItemInfo> listObjectInfo(
      String bucketName, String objectNamePrefix, String delimiter, long maxResults)
      throws IOException {
    List<GoogleCloudStorageItemInfo> result;

    if (options.isListCachingEnabled()) {
      result = cache.getList(bucketName, objectNamePrefix);

      if (result == null) {
        result = super.listObjectInfo(bucketName, objectNamePrefix, null);
        cache.putList(bucketName, objectNamePrefix, result);
      }

      filter(result, bucketName, objectNamePrefix, delimiter);

      if (maxResults > 0 && result.size() > maxResults) {
        result = result.subList(0, (int) maxResults);
      }
    } else {
      result = super.listObjectInfo(bucketName, objectNamePrefix, delimiter, maxResults);
      for (GoogleCloudStorageItemInfo item : result) {
        cache.putItem(item);
      }
    }

    return result;
  }
997654
def get_all_objects_in_bucket(
        aws_bucket_name,
        s3_client=None,
        max_keys=1000
):
    
    logger.debug("Retrieving bucket object list")

    if not s3_client:
        s3_client, s3_resource = get_s3_client()

    obj_dict = {}
    paginator = s3_client.get_paginator('list_objects')
    page_iterator = paginator.paginate(Bucket=aws_bucket_name)
    for page in page_iterator:
        key_list = page.get('Contents', [])
        logger.debug("Loading page with {} keys".format(len(key_list)))
        for obj in key_list:
            obj_dict[obj.get('Key')] = obj
    return obj_dict
828633
def get_bucket_list():
    
    args = parser.parse_args()
    for b in s3_conn(args.aws_access_key_id, args.aws_secret_access_key).get_all_buckets():
        print(''.join([i if ord(i) < 128 else ' ' for i in b.name]))