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

com.ksyun.ks3.service.request.PutBucketStorageQuotaRequest Maven / Gradle / Ivy

package com.ksyun.ks3.service.request;

import com.ksyun.ks3.http.HttpMethod;
import com.ksyun.ks3.http.Request;
import com.ksyun.ks3.utils.StringUtils;
import com.ksyun.ks3.utils.XmlWriter;

import java.io.ByteArrayInputStream;

import static com.ksyun.ks3.exception.client.ClientIllegalArgumentExceptionGenerator.notNull;

public class PutBucketStorageQuotaRequest extends Ks3WebServiceRequest {

    private String bucketName;

    private Long storageQuota;

    public PutBucketStorageQuotaRequest() {

    }

    public PutBucketStorageQuotaRequest(String bucketName, Long storageQuota) {
        this.bucketName = bucketName;
        this.storageQuota = storageQuota;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public Long getStorageQuota() {
        return storageQuota;
    }

    public void setStorageQuota(Long storageQuota) {
        this.storageQuota = storageQuota;
    }

    public void buildRequest(Request request) {
        request.setMethod(HttpMethod.PUT);
        request.setBucket(bucketName);
        request.addQueryParam("quota", "");
        XmlWriter writer = new XmlWriter();
        writer.start("Quota").start("StorageQuota").value(String.valueOf(this.storageQuota)).end().end();
        request.setContent(new ByteArrayInputStream(writer.toString().getBytes()));
    }

    public void validateParams() {
        if (StringUtils.isBlank(this.bucketName))
            throw notNull("bucketname");
        if (this.storageQuota == null)
            throw notNull("quota");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy