Skip to content

Commit 7daf5cb

Browse files
committed
Feedback++++
1 parent 91ad89a commit 7daf5cb

File tree

1 file changed

+7
-11
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/bundle

1 file changed

+7
-11
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleReader.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
2121
import java.io.InputStream;
22+
import java.io.InputStreamReader;
2223
import java.nio.ByteBuffer;
2324
import java.nio.charset.Charset;
2425
import org.json.JSONException;
@@ -38,6 +39,7 @@ public class BundleReader {
3839

3940
private final BundleSerializer serializer;
4041
private final InputStream bundleInputStream;
42+
private final InputStreamReader dataReader;
4143

4244
@Nullable BundleMetadata metadata;
4345
private ByteBuffer buffer;
@@ -46,6 +48,7 @@ public class BundleReader {
4648
public BundleReader(BundleSerializer serializer, InputStream bundleInputStream) {
4749
this.serializer = serializer;
4850
this.bundleInputStream = bundleInputStream;
51+
this.dataReader = new InputStreamReader(this.bundleInputStream);
4952
buffer = ByteBuffer.allocate(BUFFER_CAPACITY);
5053

5154
buffer.flip(); // Start the buffer in "reading mode"
@@ -135,9 +138,9 @@ private BundleElement readNextElement() throws IOException, JSONException {
135138
throw abort("Reached the end of bundle when a length string is expected.");
136139
}
137140

138-
byte[] c = new byte[nextOpenBracket];
139-
buffer.get(c);
140-
return UTF8_CHARSET.decode(ByteBuffer.wrap(c)).toString();
141+
byte[] b = new byte[nextOpenBracket];
142+
buffer.get(b);
143+
return UTF8_CHARSET.decode(ByteBuffer.wrap(b)).toString();
141144
}
142145

143146
/** Returns the index of the first open bracket, or -1 if none is found. */
@@ -193,16 +196,9 @@ private String readJsonString(int bytesToRead) throws IOException {
193196
private boolean pullMoreData() throws IOException {
194197
buffer.compact();
195198

196-
int available = bundleInputStream.available();
197-
int bytesToRead = Math.min(available, buffer.remaining());
198-
// `available` is an estimation, we still try to read if the estimation is 0, to move things
199-
// forward.
200-
if (available == 0) {
201-
bytesToRead = buffer.remaining();
202-
}
203199
int bytesRead =
204200
bundleInputStream.read(
205-
buffer.array(), buffer.arrayOffset() + buffer.position(), bytesToRead);
201+
buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
206202
boolean readSuccess = bytesRead > 0;
207203
if (readSuccess) {
208204
buffer.position(buffer.position() + bytesRead);

0 commit comments

Comments
 (0)