Example usage for com.amazonaws.services.s3.model ObjectMetadata getContentEncoding

List of usage examples for com.amazonaws.services.s3.model ObjectMetadata getContentEncoding

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ObjectMetadata getContentEncoding.

Prototype

public String getContentEncoding() 

Source Link

Document

<p> Gets the optional Content-Encoding HTTP header specifying what content encodings have been applied to the object and what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type field.

Usage

From source file:com.emc.ecs.sync.model.object.S3SyncObject.java

License:Open Source License

protected SyncMetadata toSyncMeta(ObjectMetadata s3meta) {
    SyncMetadata meta = new SyncMetadata();

    meta.setCacheControl(s3meta.getCacheControl());
    meta.setContentDisposition(s3meta.getContentDisposition());
    meta.setContentEncoding(s3meta.getContentEncoding());
    if (s3meta.getContentMD5() != null)
        meta.setChecksum(new Checksum("MD5", s3meta.getContentMD5()));
    meta.setContentType(s3meta.getContentType());
    meta.setHttpExpires(s3meta.getHttpExpiresDate());
    meta.setExpirationDate(s3meta.getExpirationTime());
    meta.setModificationTime(s3meta.getLastModified());
    meta.setContentLength(s3meta.getContentLength());
    meta.setUserMetadata(toMetaMap(s3meta.getUserMetadata()));

    return meta;/*from   www  .  ja va 2s .  c om*/
}

From source file:fr.ens.biologie.genomique.eoulsan.data.protocols.S3DataProtocol.java

License:LGPL

@Override
public DataFileMetadata getMetadata(final DataFile src) throws IOException {

    if (!exists(src, true)) {
        throw new FileNotFoundException("File not found: " + src);
    }/* w  w  w.java2  s  .c  o m*/

    final ObjectMetadata md = new S3URL(src).getMetaData();

    final SimpleDataFileMetadata result = new SimpleDataFileMetadata();
    result.setContentLength(md.getContentLength());
    result.setLastModified(md.getLastModified().getTime());
    result.setContentType(md.getContentType());
    result.setContentEncoding(md.getContentEncoding());
    result.setDataFormat(DataFormatRegistry.getInstance().getDataFormatFromFilename(src.getName()));

    return result;
}

From source file:io.konig.camel.aws.s3.DeleteObjectEndpoint.java

License:Apache License

public Exchange createExchange(ExchangePattern pattern, final S3Object s3Object) {
    LOG.trace("Getting object with key [{}] from bucket [{}]...", s3Object.getKey(), s3Object.getBucketName());

    ObjectMetadata objectMetadata = s3Object.getObjectMetadata();

    LOG.trace("Got object [{}]", s3Object);

    Exchange exchange = super.createExchange(pattern);
    Message message = exchange.getIn();/*from ww w  .  ja v a 2s.c  o m*/

    if (configuration.isIncludeBody()) {
        message.setBody(s3Object.getObjectContent());
    } else {
        message.setBody(null);
    }

    message.setHeader(S3Constants.KEY, s3Object.getKey());
    message.setHeader(S3Constants.BUCKET_NAME, s3Object.getBucketName());
    message.setHeader(S3Constants.E_TAG, objectMetadata.getETag());
    message.setHeader(S3Constants.LAST_MODIFIED, objectMetadata.getLastModified());
    message.setHeader(S3Constants.VERSION_ID, objectMetadata.getVersionId());
    message.setHeader(S3Constants.CONTENT_TYPE, objectMetadata.getContentType());
    message.setHeader(S3Constants.CONTENT_MD5, objectMetadata.getContentMD5());
    message.setHeader(S3Constants.CONTENT_LENGTH, objectMetadata.getContentLength());
    message.setHeader(S3Constants.CONTENT_ENCODING, objectMetadata.getContentEncoding());
    message.setHeader(S3Constants.CONTENT_DISPOSITION, objectMetadata.getContentDisposition());
    message.setHeader(S3Constants.CACHE_CONTROL, objectMetadata.getCacheControl());
    message.setHeader(S3Constants.S3_HEADERS, objectMetadata.getRawMetadata());
    message.setHeader(S3Constants.SERVER_SIDE_ENCRYPTION, objectMetadata.getSSEAlgorithm());
    message.setHeader(S3Constants.USER_METADATA, objectMetadata.getUserMetadata());
    message.setHeader(S3Constants.EXPIRATION_TIME, objectMetadata.getExpirationTime());
    message.setHeader(S3Constants.REPLICATION_STATUS, objectMetadata.getReplicationStatus());
    message.setHeader(S3Constants.STORAGE_CLASS, objectMetadata.getStorageClass());

    /**
    * If includeBody != true, it is safe to close the object here. If
    * includeBody == true, the caller is responsible for closing the stream
    * and object once the body has been fully consumed. As of 2.17, the
    * consumer does not close the stream or object on commit.
    */
    if (!configuration.isIncludeBody()) {
        IOHelper.close(s3Object);
    } else {
        if (configuration.isAutocloseBody()) {
            exchange.addOnCompletion(new SynchronizationAdapter() {
                @Override
                public void onDone(Exchange exchange) {
                    IOHelper.close(s3Object);
                }
            });
        }
    }

    return exchange;
}

From source file:littleware.apps.fishRunner.FishApp.java

License:LGPL

/**
 * Download the given S3 URI to the given dest file
 * //from   w w  w . ja va  2s.c o m
 * @param resourcePath path string either starts with s3:// or treated as local path
 * @param destFile
 * @return local file to work with if resource exists, otherwise throws ConfigException
 */
private File downloadHelper(String resourcePath, File destFile) throws ConfigException {
    if (resourcePath.startsWith("s3://")) {
        try {
            final URI s3URI = new java.net.URI(resourcePath);
            final GetObjectRequest req = new GetObjectRequest(s3URI.getHost(),
                    s3URI.getPath().replaceAll("//+", "/").replaceAll("^/+", "").replaceAll("/+$", ""));

            final ObjectMetadata meta = s3.getObject(req, destFile);
            if (null == meta) {
                throw new RuntimeException("Unable to access resource: " + resourcePath);
            }

            if ("gzip".equalsIgnoreCase(meta.getContentEncoding())) {
                // need to unzip the war ...
                final File temp = new File(destFile.getParentFile(), destFile.getName() + ".gz");
                temp.delete();
                destFile.renameTo(temp);
                try (final InputStream gzin = new java.util.zip.GZIPInputStream(new FileInputStream(temp));) {
                    Files.copy(gzin, destFile.toPath());
                }
            }

            return destFile;
        } catch (URISyntaxException | IOException ex) {
            throw new RuntimeException("Failed parsing: " + resourcePath, ex);
        }
    } else {
        final File resourceFile = new File(resourcePath);
        if (!resourceFile.exists()) {
            throw new RuntimeException("Unable to access resource: " + resourcePath);
        }
        return resourceFile;
    }
}

From source file:org.apache.beam.sdk.io.aws.s3.S3FileSystem.java

License:Apache License

private PathWithEncoding getPathContentEncoding(S3ResourceId path) {
    ObjectMetadata s3Metadata;
    try {/*from ww w .j  a  v  a2  s  . co m*/
        s3Metadata = getObjectMetadata(path);
    } catch (AmazonClientException e) {
        if (e instanceof AmazonS3Exception && ((AmazonS3Exception) e).getStatusCode() == 404) {
            return PathWithEncoding.create(path, new FileNotFoundException());
        }
        return PathWithEncoding.create(path, new IOException(e));
    }
    return PathWithEncoding.create(path, Strings.nullToEmpty(s3Metadata.getContentEncoding()));
}

From source file:org.apache.beam.sdk.io.aws.s3.S3FileSystem.java

License:Apache License

@VisibleForTesting
MatchResult matchNonGlobPath(S3ResourceId path) {
    ObjectMetadata s3Metadata;
    try {//from   w ww .  j a v  a  2s.com
        s3Metadata = getObjectMetadata(path);
    } catch (AmazonClientException e) {
        if (e instanceof AmazonS3Exception && ((AmazonS3Exception) e).getStatusCode() == 404) {
            return MatchResult.create(MatchResult.Status.NOT_FOUND, new FileNotFoundException());
        }
        return MatchResult.create(MatchResult.Status.ERROR, new IOException(e));
    }

    return MatchResult.create(MatchResult.Status.OK,
            ImmutableList.of(createBeamMetadata(
                    path.withSize(s3Metadata.getContentLength()).withLastModified(s3Metadata.getLastModified()),
                    Strings.nullToEmpty(s3Metadata.getContentEncoding()))));
}

From source file:org.apache.camel.component.aws.s3.S3Endpoint.java

License:Apache License

public Exchange createExchange(ExchangePattern pattern, S3Object s3Object) {
    LOG.trace("Getting object with key [{}] from bucket [{}]...", s3Object.getKey(), s3Object.getBucketName());

    ObjectMetadata objectMetadata = s3Object.getObjectMetadata();

    LOG.trace("Got object [{}]", s3Object);

    Exchange exchange = new DefaultExchange(this, pattern);
    Message message = exchange.getIn();/* www. j a  v  a 2s.c  o  m*/
    message.setBody(s3Object.getObjectContent());
    message.setHeader(S3Constants.KEY, s3Object.getKey());
    message.setHeader(S3Constants.BUCKET_NAME, s3Object.getBucketName());
    message.setHeader(S3Constants.E_TAG, objectMetadata.getETag());
    message.setHeader(S3Constants.LAST_MODIFIED, objectMetadata.getLastModified());
    message.setHeader(S3Constants.VERSION_ID, objectMetadata.getVersionId());
    message.setHeader(S3Constants.CONTENT_TYPE, objectMetadata.getContentType());
    message.setHeader(S3Constants.CONTENT_MD5, objectMetadata.getContentMD5());
    message.setHeader(S3Constants.CONTENT_LENGTH, objectMetadata.getContentLength());
    message.setHeader(S3Constants.CONTENT_ENCODING, objectMetadata.getContentEncoding());
    message.setHeader(S3Constants.CONTENT_DISPOSITION, objectMetadata.getContentDisposition());
    message.setHeader(S3Constants.CACHE_CONTROL, objectMetadata.getCacheControl());

    return exchange;
}

From source file:org.duracloud.s3storage.S3StorageProvider.java

License:Apache License

private Map<String, String> prepContentProperties(ObjectMetadata objMetadata) {
    Map<String, String> contentProperties = new HashMap<>();

    // Set the user properties
    Map<String, String> userProperties = objMetadata.getUserMetadata();
    for (String metaName : userProperties.keySet()) {
        String metaValue = userProperties.get(metaName);
        contentProperties.put(getWithSpace(decodeHeaderKey(metaName)), decodeHeaderValue(metaValue));
    }//  w  ww.jav a 2 s  .c om

    // Set the response metadata
    Map<String, Object> responseMeta = objMetadata.getRawMetadata();
    for (String metaName : responseMeta.keySet()) {
        Object metaValue = responseMeta.get(metaName);
        if (metaValue instanceof String) {
            contentProperties.put(metaName, (String) metaValue);
        }
    }

    // Set MIMETYPE
    String contentType = objMetadata.getContentType();
    if (contentType != null) {
        contentProperties.put(PROPERTIES_CONTENT_MIMETYPE, contentType);
        contentProperties.put(Headers.CONTENT_TYPE, contentType);
    }

    // Set CONTENT_ENCODING
    String encoding = objMetadata.getContentEncoding();
    if (encoding != null) {
        contentProperties.put(Headers.CONTENT_ENCODING, encoding);
    }

    // Set SIZE
    long contentLength = objMetadata.getContentLength();
    if (contentLength >= 0) {
        String size = String.valueOf(contentLength);
        contentProperties.put(PROPERTIES_CONTENT_SIZE, size);
        contentProperties.put(Headers.CONTENT_LENGTH, size);
    }

    // Set CHECKSUM
    String checksum = objMetadata.getETag();
    if (checksum != null) {
        String eTagValue = getETagValue(checksum);
        contentProperties.put(PROPERTIES_CONTENT_CHECKSUM, eTagValue);
        contentProperties.put(PROPERTIES_CONTENT_MD5, eTagValue);
        contentProperties.put(Headers.ETAG, eTagValue);
    }

    // Set MODIFIED
    Date modified = objMetadata.getLastModified();
    if (modified != null) {
        String modDate = formattedDate(modified);
        contentProperties.put(PROPERTIES_CONTENT_MODIFIED, modDate);
        contentProperties.put(Headers.LAST_MODIFIED, modDate);
    }

    return contentProperties;
}

From source file:org.openflamingo.fs.s3.S3Utils.java

License:Apache License

/**
 * Bucket  ./*from   w  w w .  j  a v  a  2 s . com*/
 *
 * @param client     Amazon S3 Client
 * @param bucketName Bucket Name
 */
public static Map<String, String> getBucketInfo(AmazonS3Client client, String bucketName) {
    Bucket bucket = getBucket(client, bucketName);
    if (bucket == null) {
        return null;
    }

    ObjectMetadata objectMetadata = client.getObjectMetadata(bucketName, "");

    Map<String, String> map = new HashMap<String, String>();
    map.put("name", bucket.getName());
    map.put("ownerName", bucket.getOwner().getDisplayName());
    map.put("ownerId", bucket.getOwner().getId());
    setValue("create", bucket.getCreationDate(), map);
    setValue("location", client.getBucketLocation(bucketName), map);
    setValue("version", objectMetadata.getVersionId(), map);
    setValue("contentDisposition", objectMetadata.getContentDisposition(), map);
    setValue("contentType", objectMetadata.getContentType(), map);
    setValue("etag", objectMetadata.getETag(), map);
    setValue("contentEncoding", objectMetadata.getContentEncoding(), map);
    setValue("contentLength", objectMetadata.getContentLength(), map);
    setValue("lastModified", objectMetadata.getLastModified(), map);

    return map;
}

From source file:org.openflamingo.fs.s3.S3Utils.java

License:Apache License

/**
 * Object  ./*from  ww w. j a v  a 2s.c om*/
 *
 * @param client     Amazon S3 Client
 * @param bucketName Bucket Name
 */
public static Map<String, String> getObject(AmazonS3Client client, String bucketName, String objectKey) {
    S3Object object = client.getObject(bucketName, objectKey);
    ObjectMetadata objectMetadata = object.getObjectMetadata();

    Map<String, String> map = new HashMap<String, String>();

    if (!object.getKey().endsWith("/")) {
        String qualifiedPath = "/" + bucketName + "/" + object.getKey();
        map.put("bucketName", object.getBucketName());
        map.put("name", FileUtils.getFilename(qualifiedPath));
        map.put("path", qualifiedPath);
    } else {
        map.put("bucketName", object.getBucketName());
        map.put("name", object.getKey());
        map.put("name", "/" + bucketName + "/" + object.getKey());
    }

    setValue("redirectionLocation", object.getRedirectLocation(), map);
    setValue("version", objectMetadata.getVersionId(), map);
    setValue("contentDisposition", objectMetadata.getContentDisposition(), map);
    setValue("contentType", objectMetadata.getContentType(), map);
    setValue("etag", objectMetadata.getETag(), map);
    setValue("contentEncoding", objectMetadata.getContentEncoding(), map);
    setValue("contentLength", objectMetadata.getContentLength(), map);
    setValue("lastModified", objectMetadata.getLastModified(), map);
    return map;
}