Skip to content

Commit 677906f

Browse files
authored
Merge pull request #208 from sxci/rels_7.0.10
断点上传skip已上传部分。release
2 parents 1144aca + 3420da2 commit 677906f

File tree

7 files changed

+237
-119
lines changed

7 files changed

+237
-119
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#Changelog
22

3+
## 7.0.10 (2016-06-27)
4+
### 修正
5+
* 断点上传,skip 已上传部分
6+
37
## 7.0.9 (2016-04-22)
48
### 增加
59
* 强制copy或者move

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ POM_DEVELOPER_ID=qiniu
1616
POM_DEVELOPER_NAME=Qiniu
1717

1818
POM_ARTIFACT_ID=qiniu-java-sdk
19-
POM_NAME=java-sdk
19+
POM_NAME=qiniu-java-sdk
2020
POM_PACKAGING=jar

src/main/java/com/qiniu/common/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public final class Config {
88

9-
public static final String VERSION = "7.0.9";
9+
public static final String VERSION = "7.0.10";
1010
/**
1111
* 断点上传时的分块大小(默认的分块大小, 不允许改变)
1212
*/

src/main/java/com/qiniu/storage/ResumeUploader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public Response upload() throws QiniuException {
7474
}
7575
boolean retry = false;
7676
int contextIndex = blockIdx(uploaded);
77+
try {
78+
file.skip(uploaded);
79+
} catch (IOException e) {
80+
close();
81+
throw new QiniuException(e);
82+
}
7783
while (uploaded < size) {
7884
int blockSize = nextBlockSize(uploaded);
7985
try {

src/test/java/com/qiniu/TempFile.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.FileOutputStream;
55
import java.io.IOException;
6+
import java.util.Random;
67

78
/**
89
* Created by bailong on 14/10/11.
@@ -11,6 +12,8 @@ public final class TempFile {
1112
private TempFile() {
1213
}
1314

15+
static final Random r = new Random();
16+
1417
public static void remove(File f) {
1518
f.delete();
1619
}
@@ -22,7 +25,62 @@ public static File createFile(int kiloSize) throws IOException {
2225
File f = File.createTempFile("qiniu_" + kiloSize + "k", "tmp");
2326
f.createNewFile();
2427
fos = new FileOutputStream(f);
25-
byte[] b = getByte();
28+
byte[] b = getByte((byte) r.nextInt());
29+
long s = 0;
30+
while (s < size) {
31+
int l = (int) Math.min(b.length, size - s);
32+
fos.write(b, 0, l);
33+
s += l;
34+
// 随机生成的文件的每一段(<4M)都不一样
35+
b = getByte((byte) r.nextInt());
36+
}
37+
fos.flush();
38+
return f;
39+
} finally {
40+
if (fos != null) {
41+
try {
42+
fos.close();
43+
} catch (IOException e) {
44+
e.printStackTrace();
45+
}
46+
}
47+
}
48+
}
49+
50+
private static byte[] getByte(byte b) {
51+
int len = 498 * 4;
52+
byte[] bs = new byte[len];
53+
54+
for (int i = 1; i < len; i++) {
55+
bs[i] = b;
56+
}
57+
58+
bs[10] = (byte) r.nextInt();
59+
bs[9] = (byte) r.nextInt();
60+
bs[8] = (byte) r.nextInt();
61+
bs[7] = (byte) r.nextInt();
62+
bs[6] = (byte) r.nextInt();
63+
bs[5] = (byte) r.nextInt();
64+
bs[4] = (byte) r.nextInt();
65+
bs[3] = (byte) r.nextInt();
66+
bs[3] = (byte) r.nextInt();
67+
bs[1] = (byte) r.nextInt();
68+
bs[0] = (byte) r.nextInt();
69+
70+
bs[len - 2] = '\r';
71+
bs[len - 1] = '\n';
72+
return bs;
73+
}
74+
75+
76+
public static File createFileOld(int kiloSize) throws IOException {
77+
FileOutputStream fos = null;
78+
try {
79+
long size = (long) (1024 * kiloSize);
80+
File f = File.createTempFile("qiniu_" + kiloSize + "k", "tmp");
81+
f.createNewFile();
82+
fos = new FileOutputStream(f);
83+
byte[] b = getByteOld();
2684
long s = 0;
2785
while (s < size) {
2886
int l = (int) Math.min(b.length, size - s);
@@ -42,7 +100,7 @@ public static File createFile(int kiloSize) throws IOException {
42100
}
43101
}
44102

45-
private static byte[] getByte() {
103+
private static byte[] getByteOld() {
46104
byte[] b = new byte[1024 * 4];
47105
b[0] = 'A';
48106
for (int i = 1; i < 1024 * 4; i++) {

0 commit comments

Comments
 (0)