package com.microsoft.onedrive.apiexplorer;

import java.io.IOException;
import java.io.OutputStream;

import retrofit.mime.TypedByteArray;

/**
 * Tracks progress as this byte array is written
 */
public class ProgressiveTypedByteArray extends TypedByteArray  {
    /**
     * Default buffer size
     */
    public static final int DEFAULT_BUFFER_SIZE = 4096;

    /**
     * Listens for progress of this array being written
     */
    private final ProgressListener mListener;

    /**
     * Constructs a new typed byte array.  Sets mimeType to {@code application/unknown} if absent.
     *
     * @param mimeType The mime type of this byte array
     * @param bytes The bytes that represent it
     * @param listener The progress listener
     * @throws NullPointerException if bytes are null
     */
    public ProgressiveTypedByteArray(final String mimeType, final byte[] bytes, final ProgressListener listener) {
        super(mimeType, bytes);
        this.mListener = listener;
    }

    @Override
    public void writeTo(final OutputStream out) throws IOException {
        final byte[] sourceBytes = this.getBytes();
        int writtenSoFar = 0;

        while (true) {
            final int toWrite = Math.min(DEFAULT_BUFFER_SIZE, sourceBytes.length - writtenSoFar);
            if (toWrite <= 0) {
                break;
            }
            out.write(sourceBytes, writtenSoFar, toWrite);
            writtenSoFar = writtenSoFar + toWrite;
            this.mListener.onProgress(writtenSoFar, sourceBytes.length);
        }
    }
}

@@ -1167,20 +1167,31 @@
     
-while (true)
+int toWrite;%0A        do
  %7B%0A 
@@ -1201,26 +1201,16 @@
         
-final int 
 toWrite 
@@ -1281,77 +1281,8 @@
 r);%0A
-            if (toWrite %3C= 0) %7B%0A                break;%0A            %7D%0A
     
@@ -1469,16 +1469,37 @@
        %7D
+ while (toWrite %3E 0);
 %0A    %7D%0A%7D

Remove while(true)