|
@@ -36,10 +36,6 @@ import java.net.MalformedURLException;
|
36
|
36
|
import java.net.SocketException;
|
37
|
37
|
import java.net.SocketTimeoutException;
|
38
|
38
|
import java.net.URL;
|
39
|
|
-import java.nio.ByteBuffer;
|
40
|
|
-import java.nio.charset.CharacterCodingException;
|
41
|
|
-import java.nio.charset.Charset;
|
42
|
|
-import java.nio.charset.CharsetEncoder;
|
43
|
39
|
import java.security.KeyStore;
|
44
|
40
|
import java.util.ArrayList;
|
45
|
41
|
import java.util.Arrays;
|
|
@@ -502,28 +498,12 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
502
|
498
|
// encoding will somehow break the UTF8 string format, to encode UTF8
|
503
|
499
|
// string correctly, we should do URL encoding before BASE64.
|
504
|
500
|
byte[] b = resp.body().bytes();
|
505
|
|
- CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
|
506
|
501
|
if(responseFormat == ResponseFormat.BASE64) {
|
507
|
502
|
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
|
508
|
503
|
return;
|
509
|
504
|
}
|
510
|
|
- try {
|
511
|
|
- encoder.encode(ByteBuffer.wrap(b).asCharBuffer());
|
512
|
|
- // if the data contains invalid characters the following lines will be
|
513
|
|
- // skipped.
|
514
|
|
- String utf8 = new String(b);
|
515
|
|
- callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
|
516
|
|
- }
|
517
|
|
- // This usually mean the data is contains invalid unicode characters, it's
|
518
|
|
- // binary data
|
519
|
|
- catch(CharacterCodingException ignored) {
|
520
|
|
- if(responseFormat == ResponseFormat.UTF8) {
|
521
|
|
- callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, "");
|
522
|
|
- }
|
523
|
|
- else {
|
524
|
|
- callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
|
525
|
|
- }
|
526
|
|
- }
|
|
505
|
+ String utf8 = new String(b);
|
|
506
|
+ callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
|
527
|
507
|
}
|
528
|
508
|
} catch (IOException e) {
|
529
|
509
|
callback.invoke("RNFetchBlob failed to encode response data to BASE64 string.", null);
|