org.jclouds.blobstore.domain.BlobBuilder Java Examples

The following examples show how to use org.jclouds.blobstore.domain.BlobBuilder. 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: AliOSSBlobStoreContextModule.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    bind(BlobStore.class).to(AliOSSBlobStore.class);
    bind(BlobBuilder.class).to(AliOSSBlobBuilder.class);
    bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
    bind(BlobUtils.class).to(BlobUtilsImpl.class);
}
 
Example #2
Source File: AliOSSBlobStore.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private Blob convertToBlob(OSSObject object) {
    BlobBuilder builder = blobBuilder(object.getKey()).payload(object.getObjectContent());
    Map<String, String> userMetadata = object.getObjectMetadata()
                                             .getUserMetadata();
    if (userMetadata != null) {
        builder.userMetadata(userMetadata);
    }
    return builder.build();
}
 
Example #3
Source File: S3ProxyHandler.java    From s3proxy with Apache License 2.0 5 votes vote down vote up
private static void addContentMetdataFromHttpRequest(
        BlobBuilder.PayloadBlobBuilder builder,
        HttpServletRequest request) {
    ImmutableMap.Builder<String, String> userMetadata =
            ImmutableMap.builder();
    for (String headerName : Collections.list(request.getHeaderNames())) {
        if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) {
            userMetadata.put(
                    headerName.substring(USER_METADATA_PREFIX.length()),
                    Strings.nullToEmpty(request.getHeader(headerName)));
        }
    }
    builder.cacheControl(request.getHeader(
                    HttpHeaders.CACHE_CONTROL))
            .contentDisposition(request.getHeader(
                    HttpHeaders.CONTENT_DISPOSITION))
            .contentEncoding(request.getHeader(
                    HttpHeaders.CONTENT_ENCODING))
            .contentLanguage(request.getHeader(
                    HttpHeaders.CONTENT_LANGUAGE))
            .userMetadata(userMetadata.build());
    String contentType = request.getContentType();
    if (contentType != null) {
        builder.contentType(contentType);
    }
    long expires = request.getDateHeader(HttpHeaders.EXPIRES);
    if (expires != -1) {
        builder.expires(new Date(expires));
    }
}
 
Example #4
Source File: BlobStoreManagedLedgerOffloader.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private static void addVersionInfo(BlobBuilder blobBuilder, Map<String, String> userMetadata) {
    ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder();
    metadataBuilder.putAll(userMetadata);
    metadataBuilder.put(METADATA_FORMAT_VERSION_KEY.toLowerCase(), CURRENT_VERSION);
    blobBuilder.userMetadata(metadataBuilder.build());
}
 
Example #5
Source File: S3ProxyHandler.java    From s3proxy with Apache License 2.0 4 votes vote down vote up
private void handleInitiateMultipartUpload(HttpServletRequest request,
        HttpServletResponse response, BlobStore blobStore,
        String containerName, String blobName)
        throws IOException, S3Exception {
    ByteSource payload = ByteSource.empty();
    BlobBuilder.PayloadBlobBuilder builder = blobStore
            .blobBuilder(blobName)
            .payload(payload);
    addContentMetdataFromHttpRequest(builder, request);
    builder.contentLength(payload.size());

    String storageClass = request.getHeader(AwsHttpHeaders.STORAGE_CLASS);
    if (storageClass == null || storageClass.equalsIgnoreCase("STANDARD")) {
        // defaults to STANDARD
    } else {
        builder.tier(StorageClass.valueOf(storageClass).toTier());
    }

    BlobAccess access;
    String cannedAcl = request.getHeader(AwsHttpHeaders.ACL);
    if (cannedAcl == null || cannedAcl.equalsIgnoreCase("private")) {
        access = BlobAccess.PRIVATE;
    } else if (cannedAcl.equalsIgnoreCase("public-read")) {
        access = BlobAccess.PUBLIC_READ;
    } else if (CANNED_ACLS.contains(cannedAcl)) {
        throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED);
    } else {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    PutOptions options = new PutOptions().setBlobAccess(access);

    MultipartUpload mpu = blobStore.initiateMultipartUpload(containerName,
            builder.build().getMetadata(), options);

    if (Quirks.MULTIPART_REQUIRES_STUB.contains(getBlobStoreType(
            blobStore))) {
        blobStore.putBlob(containerName, builder.name(mpu.id()).build(),
                options);
    }

    response.setCharacterEncoding(UTF_8);
    try (Writer writer = response.getWriter()) {
        response.setContentType(XML_CONTENT_TYPE);
        XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(
                writer);
        xml.writeStartDocument();
        xml.writeStartElement("InitiateMultipartUploadResult");
        xml.writeDefaultNamespace(AWS_XMLNS);

        writeSimpleElement(xml, "Bucket", containerName);
        writeSimpleElement(xml, "Key", blobName);
        writeSimpleElement(xml, "UploadId", mpu.id());

        xml.writeEndElement();
        xml.flush();
    } catch (XMLStreamException xse) {
        throw new IOException(xse);
    }
}