software.amazon.awssdk.services.s3.model.GetUrlRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of s3 Show documentation
Show all versions of s3 Show documentation
The AWS Java SDK for Amazon S3 module holds the client classes that are used for communicating with
Amazon Simple Storage Service
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package software.amazon.awssdk.services.s3.model;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.utils.Validate;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
* Request to generate a URL representing an object in Amazon S3.
*
* If the object identified by the given bucket and key has public read permissions,
* then this URL can be directly accessed to retrieve the object's data.
*/
@SdkPublicApi
public final class GetUrlRequest implements SdkPojo, ToCopyableBuilder {
private static final SdkField BUCKET_FIELD = SdkField
.builder(MarshallingType.STRING)
.getter(getter(GetUrlRequest::bucket))
.setter(setter(Builder::bucket))
.traits(LocationTrait.builder().location(MarshallLocation.PATH).locationName("Bucket")
.unmarshallLocationName("Bucket").build()).build();
private static final SdkField KEY_FIELD = SdkField
.builder(MarshallingType.STRING)
.getter(getter(GetUrlRequest::key))
.setter(setter(Builder::key))
.traits(LocationTrait.builder().location(MarshallLocation.GREEDY_PATH).locationName("Key")
.unmarshallLocationName("Key").build()).build();
private static final SdkField VERSION_ID_FIELD = SdkField
.builder(MarshallingType.STRING)
.memberName("VersionId")
.getter(getter(GetUrlRequest::versionId))
.setter(setter(Builder::versionId))
.traits(LocationTrait.builder().location(MarshallLocation.QUERY_PARAM).locationName("versionId")
.unmarshallLocationName("versionId").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(BUCKET_FIELD, KEY_FIELD,
VERSION_ID_FIELD));
private final String bucket;
private final String key;
private final Region region;
private final URI endpoint;
private final String versionId;
private GetUrlRequest(BuilderImpl builder) {
this.bucket = Validate.paramNotBlank(builder.bucket, "Bucket");
this.key = Validate.paramNotBlank(builder.key, "Key");
this.region = builder.region;
this.endpoint = builder.endpoint;
this.versionId = builder.versionId;
}
/**
* @return The name of the bucket for the object
*/
public String bucket() {
return bucket;
}
/**
* @return The key value for this object.
*/
public String key() {
return key;
}
/**
* @return The region value to use for constructing the URL
*/
public Region region() {
return region;
}
/**
* @return The endpoint value to use for constructing the URL
*/
public URI endpoint() {
return endpoint;
}
/**
* VersionId used to reference a specific version of the object.
*
* @return VersionId used to reference a specific version of the object.
*/
public String versionId() {
return versionId;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Bucket":
return Optional.ofNullable(clazz.cast(bucket()));
case "Key":
return Optional.ofNullable(clazz.cast(key()));
case "VersionId":
return Optional.ofNullable(clazz.cast(versionId()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy