當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectListing類代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.ObjectListing的典型用法代碼示例。如果您正苦於以下問題:Java ObjectListing類的具體用法?Java ObjectListing怎麽用?Java ObjectListing使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ObjectListing類屬於com.amazonaws.services.s3.model包,在下文中一共展示了ObjectListing類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: listObjects

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws SdkClientException, AmazonServiceException {
    listObjectsRequest = beforeClientExecution(listObjectsRequest);
    rejectNull(listObjectsRequest.getBucketName(), "The bucket name parameter must be specified when listing objects in a bucket");

    /**
     * This flag shows whether we need to url decode S3 key names. This flag is enabled
     * only when the customers don't explicitly call {@link ListObjectsRequest#setEncodingType(String)},
     * otherwise, it will be disabled for maintaining backwards compatibility.
     */
    final boolean shouldSDKDecodeResponse = listObjectsRequest.getEncodingType() == null;

    Request<ListObjectsRequest> request = createRequest(listObjectsRequest.getBucketName(), null, listObjectsRequest, HttpMethodName.GET);
    addParameterIfNotNull(request, "prefix", listObjectsRequest.getPrefix());
    addParameterIfNotNull(request, "marker", listObjectsRequest.getMarker());
    addParameterIfNotNull(request, "delimiter", listObjectsRequest.getDelimiter());
    if (listObjectsRequest.getMaxKeys() != null && listObjectsRequest.getMaxKeys().intValue() >= 0) request.addParameter("max-keys", listObjectsRequest.getMaxKeys().toString());
    request.addParameter("encoding-type", shouldSDKDecodeResponse ? Constants.URL_ENCODING : listObjectsRequest.getEncodingType());

    return invoke(request, new Unmarshallers.ListObjectsUnmarshaller(shouldSDKDecodeResponse), listObjectsRequest.getBucketName(), null);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:23,代碼來源:AmazonS3Client.java

示例2: deleteAll

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
public void deleteAll(String bucket) {
    logger.info("delete all from bucket, bucket={}", bucket);

    ObjectListing listing = s3.listObjects(new ListObjectsRequest().withBucketName(bucket));

    while (listing != null) {
        List<DeleteObjectsRequest.KeyVersion> keys = new ArrayList<>(listing.getObjectSummaries().size());
        for (S3ObjectSummary summary : listing.getObjectSummaries()) {
            String key = summary.getKey();
            logger.info("add key to deletion batch, key={}", key);
            keys.add(new DeleteObjectsRequest.KeyVersion(key));
        }
        if (!keys.isEmpty()) {
            logger.info("delete key batch");
            s3.deleteObjects(new DeleteObjectsRequest(bucket).withKeys(keys));
        }
        if (!listing.isTruncated()) return;

        listing = s3.listNextBatchOfObjects(listing);
    }
}
 
開發者ID:neowu,項目名稱:cmn-project,代碼行數:22,代碼來源:S3.java

示例3: resolveDirectoryResourceNames

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
private List<String> resolveDirectoryResourceNames(ObjectListing objectListing) {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    if (objectListing.getCommonPrefixes() != null) {
        for (String prefix : objectListing.getCommonPrefixes()) {
            /**
             * The common prefixes will also include the prefix of the <code>ObjectListing</code>
             */
            String directChild = prefix.split(Pattern.quote(objectListing.getPrefix()))[1];
            if (directChild.endsWith("/")) {
                builder.add(directChild.substring(0, directChild.length() - 1));
            } else {
                builder.add(directChild);
            }
        }
        return builder.build();
    }
    return Collections.emptyList();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:19,代碼來源:S3ResourceResolver.java

示例4: listDirectChildren

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
public List<String> listDirectChildren(URI parent) {
    S3RegionalResource s3RegionalResource = new S3RegionalResource(parent);
    String bucketName = s3RegionalResource.getBucketName();
    String s3BucketKey = s3RegionalResource.getKey();
    configureClient(s3RegionalResource);

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
        .withBucketName(bucketName)
        .withPrefix(s3BucketKey)
        .withMaxKeys(1000)
        .withDelimiter("/");
    ObjectListing objectListing = amazonS3Client.listObjects(listObjectsRequest);
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    builder.addAll(resourceResolver.resolveResourceNames(objectListing));

    while (objectListing.isTruncated()) {
        objectListing = amazonS3Client.listNextBatchOfObjects(objectListing);
        builder.addAll(resourceResolver.resolveResourceNames(objectListing));
    }
    return builder.build();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:22,代碼來源:S3Client.java

示例5: listObjects

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws AmazonClientException, AmazonServiceException {
    if ("nonExistingBucket".equals(listObjectsRequest.getBucketName()) && !nonExistingBucketCreated) {
        AmazonServiceException ex = new AmazonServiceException("Unknown bucket");
        ex.setStatusCode(404);
        throw ex; 
    }
    int capacity;
    ObjectListing objectListing = new ObjectListing();
    if (!ObjectHelper.isEmpty(listObjectsRequest.getMaxKeys()) && listObjectsRequest.getMaxKeys() != null) {
        capacity = listObjectsRequest.getMaxKeys();
    } else {
        capacity = maxCapacity;
    }
    
    for (int index = 0; index < objects.size() && index < capacity; index++) {
        S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
        s3ObjectSummary.setBucketName(objects.get(index).getBucketName());
        s3ObjectSummary.setKey(objects.get(index).getKey());
        
        objectListing.getObjectSummaries().add(s3ObjectSummary);
    }

    return objectListing;
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:26,代碼來源:AmazonS3ClientMock.java

示例6: testEmptyWithVersions

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
@Test
public void testEmptyWithVersions() throws Exception
{
    // enable versioning on the bucket
    SetBucketVersioningConfigurationRequest req = new SetBucketVersioningConfigurationRequest(
                bucketName, new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED));
    s3.setBucketVersioningConfiguration(req);
    
    // create some versions
    createVersionedObjects();
    
    // empty the bucket of it's contents but leave the bucket itself
    S3Cleaner.emptyBucket(s3, bucketName, false, offlineContext);
    
    // check the bucket is still present but empty
    assertTrue("Bucket '" + bucketName + "' should still be present", s3.doesBucketExistV2(bucketName));
    ObjectListing objects = s3.listObjects(bucketName);
    assertTrue("Bucket '" + bucketName + "' should be empty", objects.getObjectSummaries().isEmpty());
}
 
開發者ID:Alfresco,項目名稱:alfresco-lambda-java-utils,代碼行數:20,代碼來源:S3CleanerIntegrationTest.java

示例7: listUris

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
@Override
public List<URI> listUris(URI uri, Predicate<URI> uriPredicate) throws IOException {
    String bucketName = uri.getHost();
    if (client == null) {
        client = clientBuilder.client(uri);
    }
    String prefix = uri.getPath().length() > 1 ? uri.getPath().substring(1) : "";
    List<URI> uris = new ArrayList<>();
    ObjectListing list = client.listObjects(bucketName, prefix);
    addKeyUris(uris, list, uri, uriPredicate);
    while (list.isTruncated()) {
        list = client.listNextBatchOfObjects(list);
        addKeyUris(uris, list, uri, uriPredicate);
    }

    return uris;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:S3FileInput.java

示例8: listNextBatchOfObjects

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
@Override
public ObjectListing listNextBatchOfObjects(ListNextBatchOfObjectsRequest listNextBatchOfObjectsRequest)
        throws SdkClientException, AmazonServiceException {
    listNextBatchOfObjectsRequest = beforeClientExecution(listNextBatchOfObjectsRequest);
    rejectNull(listNextBatchOfObjectsRequest,
            "The request object parameter must be specified when listing the next batch of objects in a bucket");
    ObjectListing previousObjectListing = listNextBatchOfObjectsRequest.getPreviousObjectListing();

    if (!previousObjectListing.isTruncated()) {
        ObjectListing emptyListing = new ObjectListing();
        emptyListing.setBucketName(previousObjectListing.getBucketName());
        emptyListing.setDelimiter(previousObjectListing.getDelimiter());
        emptyListing.setMarker(previousObjectListing.getNextMarker());
        emptyListing.setMaxKeys(previousObjectListing.getMaxKeys());
        emptyListing.setPrefix(previousObjectListing.getPrefix());
        emptyListing.setEncodingType(previousObjectListing.getEncodingType());
        emptyListing.setTruncated(false);

        return emptyListing;
    }
    return listObjects(listNextBatchOfObjectsRequest.toListObjectsRequest());
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:23,代碼來源:AmazonS3Client.java

示例9: handle

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
 */
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<T> awsResponse = parseResponseMetadata(response);
    responseHeaders = response.getHeaders();

    if (responseUnmarshaller != null) {
        log.trace("Beginning to parse service response XML");
        T result = responseUnmarshaller.unmarshall(response.getContent());
        log.trace("Done parsing service response XML");
        awsResponse.setResult(result);
        
        if (result instanceof ObjectListing) {
        	if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED))){
        		((ObjectListing) result).setIBMSSEKPEnabled(Boolean.parseBoolean(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED)));
        	}
        	if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN))) {
        		((ObjectListing) result).setIBMSSEKPCrk(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN));
        	} 
        }
    }

    return awsResponse;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:26,代碼來源:S3XmlResponseHandler.java

示例10: testHeadersAddedToObjectListing

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK are set in the ObjectLIsting
 * response object
 * @throws Exception 
 * 
 */	
@Test
public void testHeadersAddedToObjectListing() throws Exception {
	
	Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
	S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
	HttpResponse httpResponse = new HttpResponse(null, null);
	httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");
	httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "123456");

	InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
	httpResponse.setContent(is);

	AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
	
	assertEquals(objectListing.getResult().getIBMSSEKPCrk(), "123456");
	assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), true);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:24,代碼來源:S3XmlResponseHandlerTest.java

示例11: testNullKPHeadersAreHandled

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK null headers are handled
 * 
 * @throws Exception 
 * 
 */	
@Test
public void testNullKPHeadersAreHandled() throws Exception {
	
	Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
	S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
	HttpResponse httpResponse = new HttpResponse(null, null);
	httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, null);
	httpResponse.addHeader(Headers.IBM_SSE_KP_CRK, null);

	InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
	httpResponse.setContent(is);

	AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
	
	assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
	assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:24,代碼來源:S3XmlResponseHandlerTest.java

示例12: testEmptyKPHeadersAreHandled

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK empty headers are handled
 * 
 * @throws Exception 
 * 
 */	
@Test
public void testEmptyKPHeadersAreHandled() throws Exception {
	
	Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
	S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
	HttpResponse httpResponse = new HttpResponse(null, null);

	InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
	httpResponse.setContent(is);

	AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
	
	assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
	assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:22,代碼來源:S3XmlResponseHandlerTest.java

示例13: testOnlyKPEnabledHeaderIsSet

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * Test the IBM_SSE_KP_CRK empty header is handled
 * 
 * @throws Exception 
 * 
 */	
@Test
public void testOnlyKPEnabledHeaderIsSet() throws Exception {
	
	Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
	S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
	HttpResponse httpResponse = new HttpResponse(null, null);
	httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");

	InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
	httpResponse.setContent(is);

	AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
	
	assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
	assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), true);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:23,代碼來源:S3XmlResponseHandlerTest.java

示例14: testOnlyCRKHeaderIsSet

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * Test the IBM_SSE_KP_CRK empty header is handled
 * 
 * @throws Exception 
 * 
 */	
@Test
public void testOnlyCRKHeaderIsSet() throws Exception {
	
	Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
	S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
	HttpResponse httpResponse = new HttpResponse(null, null);
	httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "34567");

	InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
	httpResponse.setContent(is);

	AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
	
	assertEquals(objectListing.getResult().getIBMSSEKPCrk(), "34567");
	assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:23,代碼來源:S3XmlResponseHandlerTest.java

示例15: shouldGetObjectListing

import com.amazonaws.services.s3.model.ObjectListing; //導入依賴的package包/類
/**
 * Tests if the list objects can be retrieved.
 */
@Test
public void shouldGetObjectListing() {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  s3Client.createBucket(BUCKET_NAME);
  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));

  final ObjectListing objectListingResult =
      s3Client.listObjects(BUCKET_NAME, UPLOAD_FILE_NAME);

  assertThat("ObjectListinig has no S3Objects.",
      objectListingResult.getObjectSummaries().size(),
      is(greaterThan(0)));
  assertThat("The Name of the first S3ObjectSummary item has not expected the key name.",
      objectListingResult.getObjectSummaries().get(0).getKey(),
      is(UPLOAD_FILE_NAME));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:20,代碼來源:AmazonClientUploadIT.java


注:本文中的com.amazonaws.services.s3.model.ObjectListing類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。