
com.qiniu.process.qoss.StatFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qsuits Show documentation
Show all versions of qsuits Show documentation
qiniu-suits is a efficient tools for qiniu api implemented by java8.
package com.qiniu.process.qoss;
import com.google.gson.*;
import com.qiniu.common.QiniuException;
import com.qiniu.convert.FileInfoToString;
import com.qiniu.convert.JsonToString;
import com.qiniu.interfaces.ITypeConvert;
import com.qiniu.process.Base;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.BucketManager.*;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.util.Auth;
import com.qiniu.util.HttpResponseUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class StatFile extends Base {
private String format;
private String separator;
private ITypeConvert typeConverter;
private BatchOperations batchOperations;
private BucketManager bucketManager;
public StatFile(String accessKey, String secretKey, Configuration configuration, String bucket, String rmPrefix,
String savePath, String format, String separator, int saveIndex) throws IOException {
super("stat", accessKey, secretKey, configuration, bucket, rmPrefix, savePath, saveIndex);
set(format, separator);
this.batchSize = 1000;
this.batchOperations = new BatchOperations();
this.bucketManager = new BucketManager(Auth.create(accessKey, secretKey), configuration.clone());
}
public void updateStat(String bucket, String format, String separator, String rmPrefix) throws IOException {
this.bucket = bucket;
set(format, separator);
this.rmPrefix = rmPrefix;
}
private void set(String format, String separator) throws IOException {
this.format = format;
if ("csv".equals(format) || "tab".equals(format)) {
this.separator = "csv".equals(format) ? "," : separator;
} else if (!"json".equals(this.format)) {
throw new IOException("please check your format for line to map.");
}
if (batchSize > 1) typeConverter = new JsonToString(format, separator, null);
else typeConverter = new FileInfoToString(format, separator, null);
}
public StatFile(String accessKey, String secretKey, Configuration configuration, String bucket, String rmPrefix,
String savePath, String format, String separator) throws IOException {
this(accessKey, secretKey, configuration, bucket, rmPrefix, savePath, format, separator, 0);
}
public StatFile clone() throws CloneNotSupportedException {
StatFile statFile = (StatFile)super.clone();
statFile.bucketManager = new BucketManager(Auth.create(accessKey, secretKey), configuration.clone());
if (batchSize > 1) {
statFile.batchOperations = new BatchOperations();
try {
statFile.typeConverter = new JsonToString(format, separator, null);
} catch (IOException e) {
throw new CloneNotSupportedException(e.getMessage() + ", init writer failed.");
}
} else {
try {
statFile.typeConverter = new FileInfoToString(format, separator, null);
} catch (IOException e) {
throw new CloneNotSupportedException(e.getMessage() + ", init writer failed.");
}
}
return statFile;
}
@Override
synchronized protected String batchResult(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy