Skip to content

Commit 0a82540

Browse files
authored
Merge pull request #397 from katestoycheva/dev
[#396] OneDrive Chunked Upload - Chunk size is not taken into consideration in case of customized input stream
2 parents e48ced7 + 795362a commit 0a82540

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,20 @@ public void upload(final List<Option> options,
168168
byte[] buffer = new byte[chunkSize];
169169

170170
while (this.readSoFar < this.streamSize) {
171-
int read = this.inputStream.read(buffer);
172-
173-
if (read == -1) {
174-
break;
171+
int buffRead = 0;
172+
173+
// inner loop is to work-around the case where read buffer size is limited to less than chunk size by a global setting
174+
while (buffRead < chunkSize) {
175+
int read = 0;
176+
read = this.inputStream.read(buffer, buffRead, chunkSize - buffRead);
177+
if (read == -1) {
178+
break;
179+
}
180+
buffRead += read;
175181
}
176182

177183
ChunkedUploadRequest request =
178-
new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, read,
184+
new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, buffRead,
179185
maxRetry, this.readSoFar, this.streamSize);
180186
ChunkedUploadResult<UploadType> result = request.upload(this.responseHandler);
181187

@@ -190,7 +196,7 @@ public void upload(final List<Option> options,
190196
break;
191197
}
192198

193-
this.readSoFar += read;
199+
this.readSoFar += buffRead;
194200
}
195201
}
196202

0 commit comments

Comments
 (0)