Skip to content

Commit 435b1ba

Browse files
刘斌刘斌
authored andcommitted
tmpfile 调整创建文件是 byte[] 大小
1 parent 1261a85 commit 435b1ba

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static File createFile(int kiloSize) throws IOException {
3131
int l = (int) Math.min(b.length, size - s);
3232
fos.write(b, 0, l);
3333
s += l;
34-
// 随机生成的文件的每一段(4M)都不一样
34+
// 随机生成的文件的每一段(<4M)都不一样
3535
b = getByte((byte) r.nextInt());
3636
}
3737
fos.flush();
@@ -48,9 +48,10 @@ public static File createFile(int kiloSize) throws IOException {
4848
}
4949

5050
private static byte[] getByte(byte b) {
51-
byte[] bs = new byte[1024 * 4];
51+
int len = 498 * 4;
52+
byte[] bs = new byte[len];
5253

53-
for (int i = 1; i < 1024 * 4; i++) {
54+
for (int i = 1; i < len; i++) {
5455
bs[i] = b;
5556
}
5657

@@ -66,8 +67,8 @@ private static byte[] getByte(byte b) {
6667
bs[1] = (byte) r.nextInt();
6768
bs[0] = (byte) r.nextInt();
6869

69-
bs[1024 * 4 - 2] = '\r';
70-
bs[1024 * 4 - 1] = '\n';
70+
bs[len - 2] = '\r';
71+
bs[len - 1] = '\n';
7172
return bs;
7273
}
7374

0 commit comments

Comments
 (0)