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

com.qiniu.process.qoss.ChangeStatus Maven / Gradle / Ivy

There is a newer version: 8.4.8
Show newest version
package com.qiniu.process.qoss;

import com.qiniu.common.QiniuException;
import com.qiniu.process.Base;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.BucketManager.*;
import com.qiniu.storage.Configuration;
import com.qiniu.util.Auth;
import com.qiniu.util.HttpResponseUtils;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class ChangeStatus extends Base {

    private BucketManager bucketManager;
    private BatchOperations batchOperations;
    private int status;

    public ChangeStatus(String accessKey, String secretKey, Configuration configuration, String bucket, int status,
                        String rmPrefix, String savePath, int saveIndex) throws IOException {
        super("status", accessKey, secretKey, configuration, bucket, rmPrefix, savePath, saveIndex);
        this.bucketManager = new BucketManager(Auth.create(accessKey, secretKey), configuration.clone());
        this.batchOperations = new BatchOperations();
        this.status = status;
        this.batchSize = 1000;
    }

    public void updateStatus(String bucket, int status, String rmPrefix) {
        this.bucket = bucket;
        this.status = status;
        this.rmPrefix = rmPrefix;
    }

    public ChangeStatus(String accessKey, String secretKey, Configuration configuration, String bucket, int status,
                        String rmPrefix, String savePath) throws IOException {
        this(accessKey, secretKey, configuration, bucket, status, rmPrefix, savePath, 0);
    }

    public ChangeStatus clone() throws CloneNotSupportedException {
        ChangeStatus changeStatus = (ChangeStatus)super.clone();
        changeStatus.bucketManager = new BucketManager(Auth.create(accessKey, secretKey), configuration.clone());
        if (batchSize > 1) changeStatus.batchOperations = new BatchOperations();
        return changeStatus;
    }

    @Override
    synchronized protected String batchResult(List> lineList) throws QiniuException {
        batchOperations.clearOps();
        lineList.forEach(line -> batchOperations.addChangeStatusOps(bucket, status, line.get("key")));
        return HttpResponseUtils.getResult(bucketManager.batch(batchOperations));
    }

    @Override
    protected String singleResult(Map line) throws QiniuException {
        return HttpResponseUtils.getResult(bucketManager.changeStatus(bucket, line.get("key"), status));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy