Skip to content

Commit a660372

Browse files
committed
[PDEX-950] fix the bug of put InputStream method enter infinite loop when InputStream is of zero size
1 parent c91a644 commit a660372

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ private Response upload0() throws QiniuException {
6161
long uploaded = 0;
6262
int ret = 0;
6363
boolean retry = false;
64+
boolean eof = false;
6465

65-
while (size == 0) {
66+
while (size == 0 && !eof) {
6667
int bufferIndex = 0;
6768
int blockSize = 0;
6869

70+
//try to read the full BLOCK or until the EOF
6971
while (ret != -1 && bufferIndex != blockBuffer.length) {
7072
try {
7173
blockSize = blockBuffer.length - bufferIndex;
@@ -75,6 +77,8 @@ private Response upload0() throws QiniuException {
7577
throw new QiniuException(e);
7678
}
7779
if (ret != -1) {
80+
//continue to read more
81+
//advance bufferIndex
7882
bufferIndex += ret;
7983
if (ret == 0) {
8084
try {
@@ -84,10 +88,13 @@ private Response upload0() throws QiniuException {
8488
}
8589
}
8690
} else {
91+
eof = true;
92+
//file EOF here, trigger outer while-loop finish
8793
size = uploaded + bufferIndex;
8894
}
8995
}
9096

97+
//mkblk request
9198
long crc = Crc32.bytes(blockBuffer, 0, bufferIndex);
9299
Response response = null;
93100
QiniuException temp = null;

0 commit comments

Comments
 (0)