File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
firebase-firestore/src/main/java/com/google/firebase/firestore/bundle Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -163,14 +163,19 @@ private int indexOfOpenBracket() {
163
163
private String readJsonString (int bytesToRead ) throws IOException {
164
164
ByteArrayOutputStream jsonBytes = new ByteArrayOutputStream ();
165
165
166
+ // Read at least `bytesToRead` number of bytes from the bundle into `this.buffer`, pulling more
167
+ // data if necessary.
168
+ // Exactly `bytesToRead` number of bytes will be put in `jsonBytes` after the loop completes.
166
169
int remaining = bytesToRead ;
167
170
while (remaining > 0 ) {
168
171
if (buffer .remaining () == 0 && !pullMoreData ()) {
169
172
throw abort ("Reached the end of bundle when more data was expected." );
170
173
}
171
174
175
+ // `read` is the number of bytes guaranteed to exist in `this.buffer` after the above
176
+ // call to `pullMoreData`. Copy them to `jsonBytes` and advance `this.buffer`'s position.
172
177
int read = Math .min (remaining , buffer .remaining ());
173
- jsonBytes .write (buffer .slice (). array (), 0 , read );
178
+ jsonBytes .write (buffer .array (), buffer . position () , read );
174
179
buffer .position (buffer .position () + read );
175
180
176
181
remaining -= read ;
You can’t perform that action at this time.
0 commit comments