use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method createBucket.
/*
* (non-Javadoc)
* @see
* com.amazonaws.services.s3.AmazonS3#createBucket(com.amazonaws.services
* .s3.model.CreateBucketRequest)
*/
@Override
public Bucket createBucket(CreateBucketRequest createBucketRequest) throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(createBucketRequest, "The CreateBucketRequest parameter must be specified when creating a bucket");
String bucketName = createBucketRequest.getBucketName();
String region = createBucketRequest.getRegion();
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when creating a bucket");
if (bucketName != null) {
bucketName = bucketName.trim();
}
BucketNameUtils.validateBucketName(bucketName);
final Request<CreateBucketRequest> request = createRequest(bucketName, null, createBucketRequest, HttpMethodName.PUT);
if (createBucketRequest.getAccessControlList() != null) {
addAclHeaders(request, createBucketRequest.getAccessControlList());
} else if (createBucketRequest.getCannedAcl() != null) {
request.addHeader(Headers.S3_CANNED_ACL, createBucketRequest.getCannedAcl().toString());
}
/*
* If we're talking to a region-specific endpoint other than the US, we
* *must* specify a location constraint. Try to derive the region from
* the endpoint.
*/
if (!(this.endpoint.getHost().equals(Constants.S3_HOSTNAME)) && (region == null || region.isEmpty())) {
try {
region = RegionUtils.getRegionByEndpoint(this.endpoint.getHost()).getName();
} catch (final IllegalArgumentException exception) {
// Endpoint does not correspond to a known region; send the
// request with no location constraint and hope for the best.
}
}
/*
* We can only send the CreateBucketConfiguration if we're *not*
* creating a bucket in the US region.
*/
if (region != null && !StringUtils.upperCase(region).equals(Region.US_Standard.toString())) {
final XmlWriter xml = new XmlWriter();
xml.start("CreateBucketConfiguration", "xmlns", Constants.XML_NAMESPACE);
xml.start("LocationConstraint").value(region).end();
xml.end();
final byte[] bytes = xml.getBytes();
request.addHeader(Headers.CONTENT_LENGTH, String.valueOf(bytes.length));
request.setContent(new ByteArrayInputStream(bytes));
}
invoke(request, voidResponseHandler, bucketName, null);
return new Bucket(bucketName);
}
use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.
the class AclXmlFactory method convertToXmlByteArray.
/**
* Converts the specified AccessControlList object to an XML fragment that
* can be sent to Amazon S3.
*
* @param acl The AccessControlList to convert to XML.
* @return an XML representation of the Access Control List object, suitable
* to send in a request to Amazon S3.
*/
public byte[] convertToXmlByteArray(AccessControlList acl) throws AmazonClientException {
Owner owner = acl.getOwner();
if (owner == null) {
throw new AmazonClientException("Invalid AccessControlList: missing an S3Owner");
}
XmlWriter xml = new XmlWriter();
xml.start("AccessControlPolicy", "xmlns", Constants.XML_NAMESPACE);
xml.start("Owner");
if (owner.getId() != null) {
xml.start("ID").value(owner.getId()).end();
}
if (owner.getDisplayName() != null) {
xml.start("DisplayName").value(owner.getDisplayName()).end();
}
xml.end();
xml.start("AccessControlList");
for (Grant grant : acl.getGrants()) {
xml.start("Grant");
convertToXml(grant.getGrantee(), xml);
xml.start("Permission").value(grant.getPermission().toString()).end();
xml.end();
}
xml.end();
xml.end();
return xml.getBytes();
}
use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method addNoncurrentTransitions.
private void addNoncurrentTransitions(XmlWriter xml, List<NoncurrentVersionTransition> transitions) {
if (transitions == null || transitions.isEmpty()) {
return;
}
for (final NoncurrentVersionTransition t : transitions) {
if (t != null) {
xml.start("NoncurrentVersionTransition");
if (t.getDays() != -1) {
xml.start("NoncurrentDays");
xml.value(Integer.toString(t.getDays()));
xml.end();
}
xml.start("StorageClass");
xml.value(t.getStorageClass().toString());
// </StorageClass>
xml.end();
// </NoncurrentVersionTransition>
xml.end();
}
}
}
use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method convertToXmlByteArray.
/**
* Converts the specified {@link BucketCrossOriginConfiguration} object to
* an XML fragment that can be sent to Amazon S3.
*
* @param config The {@link BucketCrossOriginConfiguration}
*/
/*
* <CORSConfiguration> <CORSRule>
* <AllowedOrigin>http://www.foobar.com</AllowedOrigin>
* <AllowedMethod>GET</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSec>
* <ExposeHeader>x-amz-server-side-encryption</ExposeHeader> </CORSRule>
* </CORSConfiguration>
*/
public byte[] convertToXmlByteArray(BucketCrossOriginConfiguration config) throws AmazonClientException {
final XmlWriter xml = new XmlWriter();
xml.start("CORSConfiguration", "xmlns", Constants.XML_NAMESPACE);
for (final CORSRule rule : config.getRules()) {
writeRule(xml, rule);
}
xml.end();
return xml.getBytes();
}
use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method addTransitions.
private void addTransitions(XmlWriter xml, List<Transition> transitions) {
if (transitions == null || transitions.isEmpty()) {
return;
}
for (final Transition t : transitions) {
if (t != null) {
xml.start("Transition");
if (t.getDate() != null) {
xml.start("Date");
xml.value(ServiceUtils.formatIso8601Date(t.getDate()));
xml.end();
}
if (t.getDays() != -1) {
xml.start("Days");
xml.value(Integer.toString(t.getDays()));
xml.end();
}
xml.start("StorageClass");
xml.value(t.getStorageClass().toString());
// <StorageClass>
xml.end();
// </Transition>
xml.end();
}
}
}
Aggregations