Skip to content

Commit 145c0e8

Browse files
author
Katerina Stoycheva
committed
[#396] Continue to read from the input stream to make sure the buffer is filled with data until the chunk size is reached before executing the chunked upload request.
1 parent 14dad55 commit 145c0e8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,19 @@ 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 read = 0;
172+
int buffRead = 0;
173+
174+
while (buffRead < chunkSize) {
175+
read = this.inputStream.read(buffer, buffRead, chunkSize - buffRead);
176+
if (read == -1) {
177+
break;
178+
}
179+
buffRead += read;
175180
}
176181

177182
ChunkedUploadRequest request =
178-
new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, read,
183+
new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, buffRead,
179184
maxRetry, this.readSoFar, this.streamSize);
180185
ChunkedUploadResult<UploadType> result = request.upload(this.responseHandler);
181186

@@ -190,7 +195,7 @@ public void upload(final List<Option> options,
190195
break;
191196
}
192197

193-
this.readSoFar += read;
198+
this.readSoFar += buffRead;
194199
}
195200
}
196201

0 commit comments

Comments
 (0)