Skip to content

Commit 61d7ab0

Browse files
wkh237bcpclone
authored andcommitted
Fix out-of-bound error when using fs.readStream with UTF8 encoding on Android wkh237#321
1 parent 623afc3 commit 61d7ab0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ public void readStream(String path, String encoding, int bufferSize, int tick, f
249249
while ((cursor = fs.read(buffer)) != -1) {
250250
encoder.encode(ByteBuffer.wrap(buffer).asCharBuffer());
251251
String chunk = new String(buffer);
252-
if(cursor != bufferSize)
252+
if(cursor != bufferSize) {
253253
chunk = chunk.substring(0, cursor);
254+
}
254255
emitStreamEvent(streamId, "data", chunk);
255256
if(tick > 0)
256257
SystemClock.sleep(tick);
@@ -292,7 +293,8 @@ public void readStream(String path, String encoding, int bufferSize, int tick, f
292293
buffer = null;
293294

294295
} catch (Exception err) {
295-
emitStreamEvent(streamId, "error", "Failed to convert data to "+encoding+" encoded string, this might due to the source data is not able to convert using this encoding.");
296+
emitStreamEvent(streamId, "warn", "Failed to convert data to "+encoding+" encoded string, this might due to the source data is not able to convert using this encoding.");
297+
err.printStackTrace();
296298
}
297299
}
298300

0 commit comments

Comments
 (0)