You have many buffers you don't need.
byte[] br = readingfile.toByteArray();
you are using to getnumberOfBytesReaded
.- Then you are getting array again:
inputStream = ... readingfile.toByteArray());
And copy it to third buffer byte data[] = new byte[bufferSize];
.
Try to use just one for all of these operations.
General advice is to set pointers of objects (and arrays) to NULL
when you don't need them anymore.
I would use code like this:
for (int partsCounter = 0; partsCounter < parts + 1; partsCounter++) {
readingfile = serviceApi.readFile(session, filehandle, offset,
(int) bufferSize);
byte[] br = readingfile.toByteArray();
int numberOfBytesReaded = br.length;
offset = offset + numberOfBytesReaded;
try {
progress.publish(""
+ (int) ((progressUpdate * 100) / tmpFileSize));
progressUpdate += numberOfBytesReaded;
fileOutputStream.write(br, 0, numberOfBytesReaded);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}