Skip to content

断点上传skip已上传部分。release #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Changelog

## 7.0.10 (2016-06-27)
### 修正
* 断点上传,skip 已上传部分

## 7.0.9 (2016-04-22)
### 增加
* 强制copy或者move
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ POM_DEVELOPER_ID=qiniu
POM_DEVELOPER_NAME=Qiniu

POM_ARTIFACT_ID=qiniu-java-sdk
POM_NAME=java-sdk
POM_NAME=qiniu-java-sdk
POM_PACKAGING=jar
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public final class Config {

public static final String VERSION = "7.0.9";
public static final String VERSION = "7.0.10";
/**
* 断点上传时的分块大小(默认的分块大小, 不允许改变)
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/qiniu/storage/ResumeUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public Response upload() throws QiniuException {
}
boolean retry = false;
int contextIndex = blockIdx(uploaded);
try {
file.skip(uploaded);
} catch (IOException e) {
close();
throw new QiniuException(e);
}
while (uploaded < size) {
int blockSize = nextBlockSize(uploaded);
try {
Expand Down
62 changes: 60 additions & 2 deletions src/test/java/com/qiniu/TempFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;

/**
* Created by bailong on 14/10/11.
Expand All @@ -11,6 +12,8 @@ public final class TempFile {
private TempFile() {
}

static final Random r = new Random();

public static void remove(File f) {
f.delete();
}
Expand All @@ -22,7 +25,62 @@ public static File createFile(int kiloSize) throws IOException {
File f = File.createTempFile("qiniu_" + kiloSize + "k", "tmp");
f.createNewFile();
fos = new FileOutputStream(f);
byte[] b = getByte();
byte[] b = getByte((byte) r.nextInt());
long s = 0;
while (s < size) {
int l = (int) Math.min(b.length, size - s);
fos.write(b, 0, l);
s += l;
// 随机生成的文件的每一段(<4M)都不一样
b = getByte((byte) r.nextInt());
}
fos.flush();
return f;
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

private static byte[] getByte(byte b) {
int len = 498 * 4;
byte[] bs = new byte[len];

for (int i = 1; i < len; i++) {
bs[i] = b;
}

bs[10] = (byte) r.nextInt();
bs[9] = (byte) r.nextInt();
bs[8] = (byte) r.nextInt();
bs[7] = (byte) r.nextInt();
bs[6] = (byte) r.nextInt();
bs[5] = (byte) r.nextInt();
bs[4] = (byte) r.nextInt();
bs[3] = (byte) r.nextInt();
bs[3] = (byte) r.nextInt();
bs[1] = (byte) r.nextInt();
bs[0] = (byte) r.nextInt();

bs[len - 2] = '\r';
bs[len - 1] = '\n';
return bs;
}


public static File createFileOld(int kiloSize) throws IOException {
FileOutputStream fos = null;
try {
long size = (long) (1024 * kiloSize);
File f = File.createTempFile("qiniu_" + kiloSize + "k", "tmp");
f.createNewFile();
fos = new FileOutputStream(f);
byte[] b = getByteOld();
long s = 0;
while (s < size) {
int l = (int) Math.min(b.length, size - s);
Expand All @@ -42,7 +100,7 @@ public static File createFile(int kiloSize) throws IOException {
}
}

private static byte[] getByte() {
private static byte[] getByteOld() {
byte[] b = new byte[1024 * 4];
b[0] = 'A';
for (int i = 1; i < 1024 * 4; i++) {
Expand Down
Loading