bug 12994: fix IndexOutOfBoundsException problem in VMDK upload

This commit is contained in:
Kelven Yang 2012-01-11 15:37:28 -08:00
parent bcd58e3ae3
commit c89f6e2936

View File

@ -335,15 +335,14 @@ public class VmwareContext {
try {
bos = new BufferedOutputStream(conn.getOutputStream());
is = new BufferedInputStream(new FileInputStream(localFileName));
int bytesAvailable = is.available();
int bufferSize = Math.min(bytesAvailable, _CHUNKSIZE);
int bufferSize = _CHUNKSIZE;
byte[] buffer = new byte[bufferSize];
while (true) {
int bytesRead = is.read(buffer, 0, bufferSize);
if (bytesRead == -1) {
break;
}
bos.write(buffer, 0, bufferSize);
}
bos.write(buffer, 0, bytesRead);
totalBytesUpdated += bytesRead;
bos.flush();
if(progressUpdater != null)