Skip to content
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
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