当前位置: 首页>>代码示例>>Java>>正文


Java AmazonS3.getBucketLocation方法代码示例

本文整理汇总了Java中com.amazonaws.services.s3.AmazonS3.getBucketLocation方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3.getBucketLocation方法的具体用法?Java AmazonS3.getBucketLocation怎么用?Java AmazonS3.getBucketLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.s3.AmazonS3的用法示例。


在下文中一共展示了AmazonS3.getBucketLocation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: regionForUri

import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
private String regionForUri(AmazonS3 client, AmazonS3URI uri) {
  String bucketRegion = client.getBucketLocation(uri.getBucket());
  Region region = Region.fromValue(bucketRegion);

  // S3 doesn't have a US East 1 region, US East 1 is really the region
  // US Standard. US Standard places the data in either an east coast
  // or west coast data center geographically closest to you.
  // SigV4 requires you to mention a region while signing a request
  // and for the S3's US standard endpoints the value to be used is "us-east-1"
  // US West 1 has an endpoint and so is treated as a stand alone region,
  // US East 1 doesn't and so is bundled into US Standard
  if (region.equals(Region.US_Standard)) {
    bucketRegion = "us-east-1";
  } else {
    bucketRegion = region.toString();
  }
  return bucketRegion;
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:19,代码来源:JceksAmazonS3ClientFactory.java

示例2: addBucketFSEntry

import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
/**
 * To reuse code for accountbased and external buckets
 * @param s3
 * @param parentConf
 * @param bucketName
 * @throws IOException
 */
private FileSystem addBucketFSEntry(AmazonS3 s3, Configuration parentConf, String bucketName) throws AmazonS3Exception, IOException {
  final String bucketRegion = s3.getBucketLocation(bucketName);
  final String projectedBucketEndPoint = "s3." + bucketRegion + ".amazonaws.com";
  String regionEndPoint = projectedBucketEndPoint;
  try {
    Region region = Region.fromValue(bucketRegion);
    com.amazonaws.regions.Region awsRegion = region.toAWSRegion();
    if (awsRegion != null) {
      regionEndPoint = awsRegion.getServiceEndpoint("s3");
    }
  } catch (IllegalArgumentException iae) {
    // try heuristic mapping if not found
    regionEndPoint = projectedBucketEndPoint;
    logger.warn("Unknown or unmapped region {} for bucket {}. Will use following fs.s3a.endpoint: {}",
      bucketRegion, bucketName, regionEndPoint);
  }
  // it could be null because no mapping from Region to aws region or there is no such region is the map of endpoints
  // not sure if latter is possible
  if (regionEndPoint == null) {
    logger.error("Could not get AWSRegion for bucket {}. Will use following fs.s3a.endpoint: " + "{} ",
      bucketName, projectedBucketEndPoint);
  }
  String location = S3_URI_SCHEMA + bucketName + "/";
  Configuration bucketConf = new Configuration(parentConf);
  bucketConf.set(ENDPOINT, (regionEndPoint != null) ? regionEndPoint : projectedBucketEndPoint);
  FileSystem.setDefaultUri(bucketConf, new Path(location).toUri());
  return FileSystem.get(bucketConf);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:36,代码来源:S3FileSystem.java


注:本文中的com.amazonaws.services.s3.AmazonS3.getBucketLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。