All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.artipie.asto.s3.S3HeadMeta Maven / Gradle / Ivy

There is a newer version: v1.17.16
Show newest version
/*
 * The MIT License (MIT) Copyright (c) 2020-2023 artipie.com
 * https://github.com/artipie/asto/LICENSE.txt
 */
package com.artipie.asto.s3;

import com.artipie.asto.Meta;
import java.util.HashMap;
import java.util.Map;
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;

/**
 * Metadata from S3 object.
 * @since 0.1
 */
final class S3HeadMeta implements Meta {

    /**
     * S3 head object response.
     */
    private final HeadObjectResponse rsp;

    /**
     * New metadata.
     * @param rsp Head response
     */
    S3HeadMeta(final HeadObjectResponse rsp) {
        this.rsp = rsp;
    }

    @Override
    public  T read(final ReadOperator opr) {
        final Map raw = new HashMap<>();
        Meta.OP_SIZE.put(raw, this.rsp.contentLength());
        // @checkstyle MethodBodyCommentsCheck (1 line)
        // ETag is a quoted MD5 of blob content according to S3 docs
        Meta.OP_MD5.put(raw, this.rsp.eTag().replaceAll("\"", ""));
        return opr.take(raw);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy