Explorar el Código

check if buffer data and content exists before trying get data from source

Artem Emelyanov hace 4 años
padre
commit
4ff2d8a293
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  1. 5
    1
      android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+ 5
- 1
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Ver fichero

600
                     if (responseBody != null) {
600
                     if (responseBody != null) {
601
                         String responseBodyString = null;
601
                         String responseBodyString = null;
602
                         try {
602
                         try {
603
-                            responseBodyString = responseBody.string();
603
+                            boolean isBufferDataExists = responseBody.source().buffer().size() > 0;
604
+                            boolean isContentExists = responseBody.contentLength() > 0;
605
+                            if (isBufferDataExists && isContentExists) {
606
+                                responseBodyString = responseBody.string();
607
+                            }
604
                         } catch(IOException exception) {
608
                         } catch(IOException exception) {
605
                             exception.printStackTrace();
609
                             exception.printStackTrace();
606
                         }
610
                         }