全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

管理存储空间存储清单(Java)

最近更新时间:2025-04-25 15:42:55

添加存储清单配置

public void putBucketInventoryConfiguration() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        // 初始化存储清单配置
        InventoryConfiguration inventoryConfiguration = new InventoryConfiguration();
        // 设置存储清单配置的ID,必须且唯一
        inventoryConfiguration.setInventoryId("inventoryId");
        // 设置存储清单配置的状态,true:启用,false:关闭
        inventoryConfiguration.setEnabled(true);
        // 设置存储清单配置的匹配范围,包括:前缀、最后修改时间的起始时间戳、最后修改时间的结束时间戳
        InventoryFilter inventoryFilter = new InventoryFilter();
        inventoryFilter.setPrefix("prefix");
        inventoryFilter.setLastModifyBeginTimeStamp(1724835000000L);
        inventoryFilter.setLastModifyEndTimeStamp(1724836005834L);
        inventoryConfiguration.setInventoryFilter(inventoryFilter);

        // 设置存储清单的保存位置、格式
        InventoryBucketDestination inventoryBucketDestination = new InventoryBucketDestination();
        inventoryBucketDestination.setBucket("destinationBucket");
        inventoryBucketDestination.setPrefix("destinationPrefix");
        inventoryBucketDestination.setFormat(InventoryFormat.CSV);
        inventoryConfiguration.setDestination(new InventoryDestination(inventoryBucketDestination));

        // 设置存储清单的调度
        InventorySchedule inventorySchedule = new InventorySchedule(InventoryFrequency.Weekly.toString());
        inventoryConfiguration.setSchedule(inventorySchedule);

        // 设置存储清单的可选字段
        inventoryConfiguration.setOptionalFields(InventoryOptionalFields.DefaultFields);
        // 设置存储清单的排序方式
        inventoryConfiguration.setOrderBy(InventoryConfiguration.ORDER_BY_KEY);
        // 发起请求,设置存储清单配置
        ks3Client.putBucketInventoryConfiguration("bucketName", inventoryConfiguration);
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 不再使用时,关闭 Ks3Client
        ks3Client.shutdown();
    }
}

API接口文档详情:点击查看

获取单个存储清单配置

public void getBucketInventoryConfiguration() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        // 获取存储空间的清单配置
        GetBucketInventoryConfigurationRequest request = new GetBucketInventoryConfigurationRequest("bucketName", "inventoryId");
        InventoryConfiguration bucketInventoryConfiguration = ks3Client.getBucketInventoryConfiguration(request);
        System.out.println("inventory configuration: " + bucketInventoryConfiguration);
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 不再使用时,关闭 Ks3Client
        ks3Client.shutdown();
    }
}

API接口文档详情:点击查看

删除存储清单配置

public void deleteBucketInventoryConfiguration() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        // 发起删除清单配置请求
        DeleteBucketInventoryConfigurationRequest request = new DeleteBucketInventoryConfigurationRequest("bucketName", "inventoryId");
        ks3Client.deleteBucketInventoryConfiguration(request);
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 不再使用时,关闭 Ks3Client
        ks3Client.shutdown();
    }
}

API接口文档详情:点击查看

列举所有存储清单配置

标准方式列举所有存储清单配置

public void listBucketInventoryConfigurations() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        String continuationToken = null;
        while (true) {
            // 发起列举清单配置请求
            ListBucketInventoryConfigurationsRequest request = new ListBucketInventoryConfigurationsRequest("bucketName");
            request.setContinuationToken(continuationToken);
            ListBucketInventoryConfigurationsResult result = ks3Client.listBucketInventoryConfigurations(request);
            System.out.println("--- list bucket inventory configurations result ---");
            System.out.println("is truncated: " + result.isTruncated());
            System.out.println("continuation token: " + result.getContinuationToken());
            System.out.println("next continuation token: " + result.getNextContinuationToken());
            for (InventoryConfiguration inventoryConfiguration : result.getInventoryConfigurationList()) {
                System.out.println("-- inventory configuration --");
                System.out.println("inventory id: " + inventoryConfiguration.getInventoryId());
                System.out.println("enabled: " + inventoryConfiguration.isEnabled());
                System.out.println("optional fields: " + inventoryConfiguration.getOptionalFields());
                System.out.println("order by: " + inventoryConfiguration.getOrderBy());
                System.out.println("schedule: " + inventoryConfiguration.getSchedule().getFrequency());
                System.out.println("- destination: ");
                InventoryBucketDestination bucketDestination = inventoryConfiguration.getDestination().getBucketDestination();
                System.out.println("  bucket: " + bucketDestination.getBucket());
                System.out.println("  prefix: " + bucketDestination.getPrefix());
                System.out.println("  format: " + bucketDestination.getFormat());
                System.out.println("- filter: ");
                InventoryFilter inventoryFilter = inventoryConfiguration.getInventoryFilter();
                System.out.println("  prefix: " + inventoryFilter.getPrefix());
                System.out.println("  last modify begin time: " + inventoryFilter.getLastModifyBeginTimeStamp());
                System.out.println("  last modify end time: " + inventoryFilter.getLastModifyEndTimeStamp());
            }

            if (result.isTruncated()) {
                continuationToken = result.getNextContinuationToken();
            } else {
                break;
            }
        }
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 不再使用时,关闭 Ks3Client
        ks3Client.shutdown();
    }
}

API接口文档详情:点击查看

使用迭代器列举所有存储清单配置

public void listBucketInventoryConfigurationsByIterator() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        // 创建清单配置迭代器
        InventoryConfigurationIterator iterator = ks3Client.newInventoryConfigurationIterator("<your-bucket>");
        while (iterator.hasNext()) {
            InventoryConfiguration inventoryConfiguration = iterator.next();
            System.out.println("-- inventory configuration --");
            System.out.println("inventory id: " + inventoryConfiguration.getInventoryId());
            System.out.println("enabled: " + inventoryConfiguration.isEnabled());
            System.out.println("optional fields: " + inventoryConfiguration.getOptionalFields());
            System.out.println("order by: " + inventoryConfiguration.getOrderBy());
            System.out.println("schedule: " + inventoryConfiguration.getSchedule().getFrequency());
            System.out.println("- destination: ");
            InventoryBucketDestination bucketDestination = inventoryConfiguration.getDestination().getBucketDestination();
            System.out.println("  bucket: " + bucketDestination.getBucket());
            System.out.println("  prefix: " + bucketDestination.getPrefix());
            System.out.println("  format: " + bucketDestination.getFormat());
            System.out.println("- filter: ");
            InventoryFilter inventoryFilter = inventoryConfiguration.getInventoryFilter();
            System.out.println("  prefix: " + inventoryFilter.getPrefix());
            System.out.println("  last modify begin time: " + inventoryFilter.getLastModifyBeginTimeStamp());
            System.out.println("  last modify end time: " + inventoryFilter.getLastModifyEndTimeStamp());
        }
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 不再使用时,关闭 Ks3Client
        ks3Client.shutdown();
    }
}

文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈