Read the requested file size completely.
This was causing failures while sharing pictures
from Picassa over Bluetooth.
Bug:5632161.
Change-Id: Ieb2697513299270b2982ebc6c9f0b367adf36d3a
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
index 6efac93..ea7e4b2 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
@@ -110,6 +110,16 @@
mThread.addShare(share);
}
+ private static int readFully(InputStream is, byte[] buffer, int size) throws IOException {
+ int done = 0;
+ while (done < size) {
+ int got = is.read(buffer, done, size - done);
+ if (got <= 0) break;
+ done += got;
+ }
+ return done;
+ }
+
private class ClientThread extends Thread {
private static final int sSleepTime = 500;
@@ -388,7 +398,7 @@
BufferedInputStream a = new BufferedInputStream(fileInfo.mInputStream, 0x4000);
if (!mInterrupted && (position != fileInfo.mLength)) {
- readLength = a.read(buffer, 0, outputBufferSize);
+ readLength = readFully(a, buffer, outputBufferSize);
mCallback.sendMessageDelayed(mCallback
.obtainMessage(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT),