com.qiniu.storage.ResumeUploadSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qiniu-java-sdk Show documentation
Show all versions of qiniu-java-sdk Show documentation
Qiniu Cloud Storage SDK for Java
package com.qiniu.storage;
import com.qiniu.common.Constants;
import com.qiniu.util.StringUtils;
import java.io.IOException;
import java.util.*;
abstract class ResumeUploadSource {
final String recordKey;
final int blockSize;
final Configuration.ResumableUploadAPIVersion resumableUploadAPIVersion;
transient Configuration config;
List blockList;
// uploadId: 此次文件上传唯一标识 【resume v2 特有】
String uploadId;
// expireAt: uploadId 有效期, 单位:秒 【resume v2 特有】
Long expireAt;
ResumeUploadSource() {
this.blockSize = 0;
this.recordKey = null;
this.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V1;
}
ResumeUploadSource(Configuration config, String recordKey) {
this.config = config;
this.blockSize = getBlockSize(config);
this.recordKey = recordKey;
this.resumableUploadAPIVersion = config.resumableUploadAPIVersion;
}
// 所有块数据是否 正在上传 或者 已上传,为 true 则说明没有需要上传的数据块
boolean isAllBlocksUploadingOrUploaded() {
if (blockList == null || blockList.size() == 0) {
return true;
}
boolean isAllBlockUploadingOrUploaded = true;
for (ResumeUploadSource.Block block : blockList) {
if (!block.isUploading && !block.isUploaded()) {
isAllBlockUploadingOrUploaded = false;
break;
}
}
return isAllBlockUploadingOrUploaded;
}
boolean isAllBlocksUploaded() {
if (blockList == null || blockList.size() == 0) {
return true;
}
boolean isAllBlockUploaded = true;
for (ResumeUploadSource.Block block : blockList) {
if (!block.isUploaded()) {
isAllBlockUploaded = false;
break;
}
}
return isAllBlockUploaded;
}
boolean couldReload() {
return false;
}
boolean reload() {
return false;
}
void clearState() {
for (ResumeUploadSource.Block block : blockList) {
block.clearState();
}
uploadId = null;
expireAt = null;
}
// 获取下一个需要上传的块
ResumeUploadSource.Block getNextUploadingBlock() throws IOException {
ResumeUploadSource.Block block = null;
for (ResumeUploadSource.Block blockP : blockList) {
if (!blockP.isUploading && !blockP.isUploaded()) {
block = blockP;
break;
}
}
return block;
}
// 关闭数据流
abstract void close() throws IOException;
// 是否为有效源文件
abstract boolean isValid();
// 获取资源大小
abstract long getSize();
// 获取文件名
abstract String getFileName();
// 是否有已上传的数据
boolean hasUploadData() {
if (blockList == null || blockList.size() == 0) {
return false;
}
boolean hasUploadData = false;
for (ResumeUploadSource.Block block : blockList) {
if (block.isUploaded()) {
hasUploadData = true;
break;
}
}
return hasUploadData;
}
boolean recoverFromRecordInfo(ResumeUploadSource source) {
return false;
}
int getBlockSize(Configuration config) {
if (resumableUploadAPIVersion == Configuration.ResumableUploadAPIVersion.V2) {
return config.resumableUploadAPIV2BlockSize;
} else {
return Constants.BLOCK_SIZE;
}
}
// 分片 V1 make file 使用
String[] getAllBlockContextList() {
String[] contextList = new String[blockList.size()];
for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i);
if (block.context != null) {
contextList[i] = block.context;
}
}
return contextList;
}
// 分片 V2 complete upload 使用
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy