Repository: microsoftgraph/msgraph-sdk-java
Issue: OneDrive Chunked Upload - Chunk size is not taken into consideration in case of customized input stream

### Expected behavior
Large files should be uploaded in chunks using the specified chunk size according to the following Javadoc comment of the upload method in **ChunkedUploadProvider** class.
/**
     * Uploads content to remote upload session based on the input stream
     *
     * @param options  the upload options
     * @param callback the progress callback invoked during uploading
     * @param **_configs  the optional configurations for the upload options. [0] should be the customized chunk_**
     *                 **_size_** and [1] should be the maxRetry for upload retry.
     * @throws IOException the IO exception that occurred during upload
     */
    ChunkedUploadProvider.upload(final List<Option> options,
                       final IProgressCallback<UploadType> callback,
                       final int... configs)


### Actual behavior
In enterprise product environment with high parallelism, input streams are often controlled on global level setting data to be read in smaller chunks, like 32 KB. For example the **InputStream read(byte[] buffer)** method reads implicitly less than the specified buffer/chunk size (e.g. reads 32 KB while chunk size is 5 MB). Currently the chunks that are being uploaded are with size equal to what is read from the stream - 32 KB. This behavior leads to too many requests in case of large files.

### Steps to reproduce the behavior
1. Use the sample code described [here](https://docs.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=java) but specify 5 MB chunk size.
2. Use following custom stream in the sample:
`InputStream fileStream = new MyInputStream(new FileInputStream(file))`
instead of:
`InputStream fileStream = new FileInputStream(file);`

public class MyInputStream extends InputStream {

    private InputStream sourceIs;

    public MyInputStream(InputStream sourceIs) {
        this.sourceIs = sourceIs;
    }

    public int read() throws IOException {
        return sourceIs.read();
    }

    @Override
    public int read(byte[] b) throws IOException {
        return super.read(b, 0, 32 * 1024);
    }
}
3. Run the sample code.

**Sample output:**
Connecting...
Uploaded 0 bytes of 5.296497344970703 MB.
Uploaded 32.0 KB of 5.296497344970703 MB.
Uploaded 64.0 KB of 5.296497344970703 MB.
Uploaded 96.0 KB of 5.296497344970703 MB.
...

**Client library versions used are:**
- microsoft-graph 1.8.0
- microsoft-graph-core 1.0.1
- microsoft-graph-auth 0.2.0

Pull request: https://github.com/microsoftgraph/msgraph-sdk-java/pull/397 

Changed files:
src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java

diff --git a/src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java b/src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java
index c9d7ee2611..c75f494aee 100644
--- a/src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java
+++ b/src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java
@@ -168,14 +168,20 @@ public class ChunkedUploadProvider<UploadType> {
         byte[] buffer = new byte[chunkSize];
 
         while (this.readSoFar < this.streamSize) {
-            int read = this.inputStream.read(buffer);
-
-            if (read == -1) {
-                break;
+            int buffRead = 0;
+
+            // inner loop is to work-around the case where read buffer size is limited to less than chunk size by a global setting
+            while (buffRead < chunkSize) {
+                int read = 0;
+                read = this.inputStream.read(buffer, buffRead, chunkSize - buffRead);
+                if (read == -1) {
+                    break;
+                }
+                buffRead += read;
             }
 
             ChunkedUploadRequest request =
-                    new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, read,
+                    new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, buffRead,
                             maxRetry, this.readSoFar, this.streamSize);
             ChunkedUploadResult<UploadType> result = request.upload(this.responseHandler);
 
@@ -190,7 +196,7 @@ public class ChunkedUploadProvider<UploadType> {
                 break;
             }
 
-            this.readSoFar += read;
+            this.readSoFar += buffRead;
         }
     }