com.amazonaws.services.s3.internal.Constants Java Examples
The following examples show how to use
com.amazonaws.services.s3.internal.Constants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrestoS3FileSystem.java From presto with Apache License 2.0 | 6 votes |
private boolean deleteObject(String key) { try { DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(getBucketName(uri), key); if (requesterPaysEnabled) { // TODO use deleteObjectRequest.setRequesterPays() when https://github.com/aws/aws-sdk-java/issues/1219 is fixed // currently the method exists, but is ineffective (doesn't set the required HTTP header) deleteObjectRequest.putCustomRequestHeader(Headers.REQUESTER_PAYS_HEADER, Constants.REQUESTER_PAYS); } s3.deleteObject(deleteObjectRequest); return true; } catch (AmazonClientException e) { return false; } }
Example #2
Source File: S3StorageDriver.java From dcos-cassandra-service with Apache License 2.0 | 6 votes |
String getEndpoint(BackupRestoreContext ctx) throws URISyntaxException { URI uri = new URI(ctx.getExternalLocation()); String scheme = uri.getScheme(); if (scheme.equals(AmazonS3Client.S3_SERVICE_NAME)) { return Constants.S3_HOSTNAME; } else { String endpoint = scheme + "://" + uri.getHost(); int port = uri.getPort(); if (port != -1) { endpoint += ":" + Integer.toString(port); } return endpoint; } }
Example #3
Source File: S3InputStream.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
public static String getBucket(URL url) { String host = url.getHost(); if (!host.endsWith(Constants.S3_HOSTNAME)) { throw new IllegalArgumentException("Not an Amazon S3 host"); } else if (host.equals(Constants.S3_HOSTNAME)) { throw new IllegalArgumentException("No bucket name specified in the host address."); } else { int hostLen = host.length(); int dividingDotPos = hostLen - Constants.S3_HOSTNAME.length(); return host.substring(0, dividingDotPos - 1); } }
Example #4
Source File: AwsS3Storage.java From ecs-sync with Apache License 2.0 | 6 votes |
private void getNextBatch() { if (listing == null) { listing = time(() -> { ListObjectsRequest request = new ListObjectsRequest().withBucketName(config.getBucketName()); request.setPrefix("".equals(prefix) ? null : prefix); // Note: AWS SDK will always set encoding-type=url, but will only decode automatically if we // leave the value null.. manually setting it here allows us to disable automatic decoding, // but if the storage actually encodes the keys, they will be corrupted.. only do this if the // storage does *not* respect the encoding-type parameter! if (!config.isUrlDecodeKeys()) request.setEncodingType(Constants.URL_ENCODING); return s3.listObjects(request); }, OPERATION_LIST_OBJECTS); } else { listing = time(() -> s3.listNextBatchOfObjects(listing), OPERATION_LIST_OBJECTS); } listing.setMaxKeys(1000); // Google Storage compatibility objectIterator = listing.getObjectSummaries().iterator(); }
Example #5
Source File: AwsS3Storage.java From ecs-sync with Apache License 2.0 | 6 votes |
private void getNextVersionBatch() { if (versionListing == null) { versionListing = time(() -> { ListVersionsRequest request = new ListVersionsRequest().withBucketName(config.getBucketName()); request.setPrefix("".equals(prefix) ? null : prefix); // Note: AWS SDK will always set encoding-type=url, but will only decode automatically if we // leave the value null.. manually setting it here allows us to disable automatic decoding, // but if the storage actually encodes the keys, they will be corrupted.. only do this if the // storage does *not* respect the encoding-type parameter! if (!config.isUrlDecodeKeys()) request.setEncodingType(Constants.URL_ENCODING); return s3.listVersions(request); }, OPERATION_LIST_VERSIONS); } else { versionListing.setMaxKeys(1000); // Google Storage compatibility versionListing = time(() -> s3.listNextBatchOfVersions(versionListing), OPERATION_LIST_VERSIONS); } versionIterator = versionListing.getVersionSummaries().iterator(); }
Example #6
Source File: S3Service.java From crate with Apache License 2.0 | 6 votes |
private AmazonS3 buildClient(final S3ClientSettings clientSettings) { final AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); builder.withCredentials(buildCredentials(LOGGER, clientSettings)); builder.withClientConfiguration(buildConfiguration(clientSettings)); final String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : Constants.S3_HOSTNAME; LOGGER.debug("using endpoint [{}]", endpoint); // If the endpoint configuration isn't set on the builder then the default behaviour is to try // and work out what region we are in and use an appropriate endpoint - see AwsClientBuilder#setRegion. // In contrast, directly-constructed clients use s3.amazonaws.com unless otherwise instructed. We currently // use a directly-constructed client, and need to keep the existing behaviour to avoid a breaking change, // so to move to using the builder we must set it explicitly to keep the existing behaviour. // // We do this because directly constructing the client is deprecated (was already deprecated in 1.1.223 too) // so this change removes that usage of a deprecated API. builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null)); return builder.build(); }
Example #7
Source File: S3StorageDriverTest.java From dcos-cassandra-service with Apache License 2.0 | 5 votes |
@Test public void testGetEndpointS3Protocol() throws URISyntaxException { BackupRestoreContext backupRestoreContext = BackupRestoreContext.create( "node-id", "name", "s3://cassandrabackup", "local-location", "account-id", "secret-key", false, "existing"); Assert.assertEquals(Constants.S3_HOSTNAME, s3StorageDriver.getEndpoint(backupRestoreContext)); }
Example #8
Source File: AwsS3Storage.java From ecs-sync with Apache License 2.0 | 5 votes |
private List<S3VersionSummary> getS3Versions(final String key) { List<S3VersionSummary> versions = new ArrayList<>(); VersionListing listing = null; do { final VersionListing fListing = listing; listing = time(() -> { if (fListing == null) { ListVersionsRequest request = new ListVersionsRequest().withBucketName(config.getBucketName()); request.withPrefix(key).withDelimiter("/"); // Note: AWS SDK will always set encoding-type=url, but will only decode automatically if we // leave the value null.. manually setting it here allows us to disable automatic decoding, // but if the storage actually encodes the keys, they will be corrupted.. only do this if the // storage does *not* respect the encoding-type parameter! if (!config.isUrlDecodeKeys()) request.setEncodingType(Constants.URL_ENCODING); return s3.listVersions(request); } else { return s3.listNextBatchOfVersions(fListing); } }, OPERATION_LIST_VERSIONS); listing.setMaxKeys(1000); // Google Storage compatibility for (final S3VersionSummary summary : listing.getVersionSummaries()) { if (summary.getKey().equals(key)) versions.add(summary); } } while (listing.isTruncated()); return versions; }
Example #9
Source File: ListS3.java From nifi with Apache License 2.0 | 5 votes |
private Record createRecordForListing(final S3VersionSummary versionSummary, final GetObjectTaggingResult taggingResult, final ObjectMetadata objectMetadata) { final Map<String, Object> values = new HashMap<>(); values.put(KEY, versionSummary.getKey()); values.put(BUCKET, versionSummary.getBucketName()); if (versionSummary.getOwner() != null) { // We may not have permission to read the owner values.put(OWNER, versionSummary.getOwner().getId()); } values.put(ETAG, versionSummary.getETag()); values.put(LAST_MODIFIED, new Timestamp(versionSummary.getLastModified().getTime())); values.put(SIZE, versionSummary.getSize()); values.put(STORAGE_CLASS, versionSummary.getStorageClass()); values.put(IS_LATEST, versionSummary.isLatest()); final String versionId = versionSummary.getVersionId(); if (versionId != null && !versionId.equals(Constants.NULL_VERSION_ID)) { values.put(VERSION_ID, versionSummary.getVersionId()); } if (taggingResult != null) { final Map<String, String> tags = new HashMap<>(); taggingResult.getTagSet().forEach(tag -> { tags.put(tag.getKey(), tag.getValue()); }); values.put(TAGS, tags); } if (objectMetadata != null) { values.put(USER_METADATA, objectMetadata.getUserMetadata()); } return new MapRecord(RECORD_SCHEMA, values); }
Example #10
Source File: S3InputStream.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
public static boolean isS3File(URL url) { String hostname = url.getHost(); return hostname.endsWith(Constants.S3_HOSTNAME); }