am fb79b7da: am 12da9d74: Fix buffer compacting in NativeDaemonConnector
Merge commit 'fb79b7dab3ccaf490e8cbb18c9feed7080e4b54f'
* commit 'fb79b7dab3ccaf490e8cbb18c9feed7080e4b54f':
Fix buffer compacting in NativeDaemonConnector
diff --git a/services/java/com/android/server/NativeDaemonConnector.java b/services/java/com/android/server/NativeDaemonConnector.java
index 249c32b..03f8dae 100644
--- a/services/java/com/android/server/NativeDaemonConnector.java
+++ b/services/java/com/android/server/NativeDaemonConnector.java
@@ -109,6 +109,10 @@
int count = inputStream.read(buffer, start, BUFFER_SIZE - start);
if (count < 0) break;
+ // Add our starting point to the count and reset the start.
+ count += start;
+ start = 0;
+
for (int i = 0; i < count; i++) {
if (buffer[i] == 0) {
String event = new String(buffer, start, i - start);
@@ -141,6 +145,9 @@
start = i + 1;
}
}
+
+ // We should end at the amount we read. If not, compact then
+ // buffer and read again.
if (start != count) {
final int remaining = BUFFER_SIZE - start;
System.arraycopy(buffer, start, buffer, 0, remaining);