浏览代码

Add comments

Ben Hsieh 8 年前
父节点
当前提交
e1cf9da54e

+ 0
- 3
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java 查看文件

21
 import okhttp3.RequestBody;
21
 import okhttp3.RequestBody;
22
 import okio.BufferedSink;
22
 import okio.BufferedSink;
23
 
23
 
24
-/**
25
- * Created by wkh237 on 2016/7/11.
26
- */
27
 public class RNFetchBlobBody extends RequestBody{
24
 public class RNFetchBlobBody extends RequestBody{
28
 
25
 
29
     InputStream requestStream;
26
     InputStream requestStream;

+ 1
- 3
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobConfig.java 查看文件

5
 
5
 
6
 import java.util.HashMap;
6
 import java.util.HashMap;
7
 
7
 
8
-/**
9
- * Created by wkh237 on 2016/5/29.
10
- */
8
+
11
 public class RNFetchBlobConfig {
9
 public class RNFetchBlobConfig {
12
 
10
 
13
     public Boolean fileCache;
11
     public Boolean fileCache;

+ 0
- 4
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobConst.java 查看文件

1
 package com.RNFetchBlob;
1
 package com.RNFetchBlob;
2
 
2
 
3
-import okhttp3.MediaType;
4
 
3
 
5
-/**
6
- * Created by wkh237 on 2016/7/11.
7
- */
8
 public class RNFetchBlobConst {
4
 public class RNFetchBlobConst {
9
     public static final String EVENT_UPLOAD_PROGRESS = "RNFetchBlobProgress-upload";
5
     public static final String EVENT_UPLOAD_PROGRESS = "RNFetchBlobProgress-upload";
10
     public static final String EVENT_PROGRESS = "RNFetchBlobProgress";
6
     public static final String EVENT_PROGRESS = "RNFetchBlobProgress";

+ 11
- 30
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java 查看文件

1
 package com.RNFetchBlob;
1
 package com.RNFetchBlob;
2
 
2
 
3
-import android.app.LoaderManager;
4
-import android.content.ContentResolver;
5
-import android.content.CursorLoader;
6
 import android.content.res.AssetFileDescriptor;
3
 import android.content.res.AssetFileDescriptor;
7
-import android.database.Cursor;
8
-import android.graphics.Path;
9
 import android.media.MediaScannerConnection;
4
 import android.media.MediaScannerConnection;
10
 import android.net.Uri;
5
 import android.net.Uri;
11
 import android.os.AsyncTask;
6
 import android.os.AsyncTask;
12
 import android.os.Environment;
7
 import android.os.Environment;
13
-import android.os.Looper;
14
 import android.os.SystemClock;
8
 import android.os.SystemClock;
15
-import android.provider.MediaStore;
16
 import android.util.Base64;
9
 import android.util.Base64;
17
 
10
 
18
 import com.RNFetchBlob.Utils.PathResolver;
11
 import com.RNFetchBlob.Utils.PathResolver;
23
 import com.facebook.react.bridge.ReadableArray;
16
 import com.facebook.react.bridge.ReadableArray;
24
 import com.facebook.react.bridge.WritableArray;
17
 import com.facebook.react.bridge.WritableArray;
25
 import com.facebook.react.bridge.WritableMap;
18
 import com.facebook.react.bridge.WritableMap;
26
-import com.facebook.react.bridge.WritableNativeArray;
27
 import com.facebook.react.modules.core.DeviceEventManagerModule;
19
 import com.facebook.react.modules.core.DeviceEventManagerModule;
28
 
20
 
29
 import java.io.File;
21
 import java.io.File;
30
 import java.io.FileInputStream;
22
 import java.io.FileInputStream;
31
-import java.io.FileNotFoundException;
32
 import java.io.FileOutputStream;
23
 import java.io.FileOutputStream;
33
 import java.io.IOException;
24
 import java.io.IOException;
34
 import java.io.InputStream;
25
 import java.io.InputStream;
35
 import java.io.OutputStream;
26
 import java.io.OutputStream;
36
-import java.io.UnsupportedEncodingException;
37
-import java.net.URLDecoder;
38
 import java.nio.charset.Charset;
27
 import java.nio.charset.Charset;
39
 import java.util.HashMap;
28
 import java.util.HashMap;
40
 import java.util.Map;
29
 import java.util.Map;
41
 import java.util.UUID;
30
 import java.util.UUID;
42
-import java.util.concurrent.BlockingDeque;
43
-import java.util.concurrent.BlockingQueue;
44
-import java.util.concurrent.LinkedBlockingQueue;
45
-import java.util.concurrent.ThreadPoolExecutor;
46
-import java.util.concurrent.TimeUnit;
47
-
48
-/**
49
- * Created by wkh237 on 2016/5/26.
50
- */
31
+
51
 public class RNFetchBlobFS {
32
 public class RNFetchBlobFS {
52
 
33
 
53
     ReactApplicationContext mCtx;
34
     ReactApplicationContext mCtx;
676
 
657
 
677
     /**
658
     /**
678
      * Create new file at path
659
      * Create new file at path
679
-     * @param path
680
-     * @param data
681
-     * @param encoding
682
-     * @param callback
660
+     * @param path The destination path of the new file.
661
+     * @param data Initial data of the new file.
662
+     * @param encoding Encoding of initial data.
663
+     * @param callback RCT bridge callback.
683
      */
664
      */
684
     static void createFile(String path, String data, String encoding, Callback callback) {
665
     static void createFile(String path, String data, String encoding, Callback callback) {
685
         try {
666
         try {
785
             return data.getBytes(Charset.forName("US-ASCII"));
766
             return data.getBytes(Charset.forName("US-ASCII"));
786
         }
767
         }
787
         else if(encoding.toLowerCase().contains("base64")) {
768
         else if(encoding.toLowerCase().contains("base64")) {
788
-            byte [] b = Base64.decode(data, Base64.NO_WRAP);
789
-            return b;
769
+            return Base64.decode(data, Base64.NO_WRAP);
770
+
790
         }
771
         }
791
         else if(encoding.equalsIgnoreCase("utf8")) {
772
         else if(encoding.equalsIgnoreCase("utf8")) {
792
             return data.getBytes(Charset.forName("UTF-8"));
773
             return data.getBytes(Charset.forName("UTF-8"));
825
     /**
806
     /**
826
      * Get input stream of the given path, when the path is a string starts with bundle-assets://
807
      * Get input stream of the given path, when the path is a string starts with bundle-assets://
827
      * the stream is created by Assets Manager, otherwise use FileInputStream.
808
      * the stream is created by Assets Manager, otherwise use FileInputStream.
828
-     * @param path
829
-     * @return
809
+     * @param path The file to open stream
810
+     * @return InputStream instance
830
      * @throws IOException
811
      * @throws IOException
831
      */
812
      */
832
     static InputStream inputStreamFromPath(String path) throws IOException {
813
     static InputStream inputStreamFromPath(String path) throws IOException {
838
 
819
 
839
     /**
820
     /**
840
      * Check if the asset or the file exists
821
      * Check if the asset or the file exists
841
-     * @param path
842
-     * @return
822
+     * @param path A file path URI string
823
+     * @return A boolean value represents if the path exists.
843
      */
824
      */
844
     static boolean isPathExists(String path) {
825
     static boolean isPathExists(String path) {
845
         if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
826
         if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {

+ 1
- 11
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobPackage.java 查看文件

1
 package com.RNFetchBlob;
1
 package com.RNFetchBlob;
2
 
2
 
3
 import com.facebook.react.ReactPackage;
3
 import com.facebook.react.ReactPackage;
4
-import com.facebook.react.bridge.Callback;
5
 import com.facebook.react.bridge.JavaScriptModule;
4
 import com.facebook.react.bridge.JavaScriptModule;
6
 import com.facebook.react.bridge.NativeModule;
5
 import com.facebook.react.bridge.NativeModule;
7
 import com.facebook.react.bridge.ReactApplicationContext;
6
 import com.facebook.react.bridge.ReactApplicationContext;
8
-import com.facebook.react.bridge.ReactContext;
9
-import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
-import com.facebook.react.bridge.ReactMethod;
11
-import com.facebook.react.bridge.ReadableArray;
12
-import com.facebook.react.bridge.ReadableMap;
13
-import com.facebook.react.bridge.ReadableMapKeySetIterator;
14
-import com.facebook.react.bridge.ReadableType;
15
 import com.facebook.react.uimanager.ViewManager;
7
 import com.facebook.react.uimanager.ViewManager;
16
 
8
 
17
 import java.util.ArrayList;
9
 import java.util.ArrayList;
18
 import java.util.Collections;
10
 import java.util.Collections;
19
 import java.util.List;
11
 import java.util.List;
20
 
12
 
21
-/**
22
- * Created by wkh237 on 2016/4/29.
23
- */
13
+
24
 public class RNFetchBlobPackage implements ReactPackage {
14
 public class RNFetchBlobPackage implements ReactPackage {
25
 
15
 
26
     @Override
16
     @Override

+ 8
- 12
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java 查看文件

48
 import okhttp3.Response;
48
 import okhttp3.Response;
49
 import okhttp3.ResponseBody;
49
 import okhttp3.ResponseBody;
50
 
50
 
51
-
52
-/**
53
- * Created by wkh237 on 2016/6/21.
54
- */
55
 public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
51
 public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
56
 
52
 
57
     enum RequestType  {
53
     enum RequestType  {
60
         AsIs,
56
         AsIs,
61
         WithoutBody,
57
         WithoutBody,
62
         Others
58
         Others
63
-    };
59
+    }
64
 
60
 
65
     enum ResponseType {
61
     enum ResponseType {
66
         KeepInMemory,
62
         KeepInMemory,
67
         FileStorage
63
         FileStorage
68
-    };
64
+    }
69
 
65
 
70
     public static HashMap<String, Call> taskTable = new HashMap<>();
66
     public static HashMap<String, Call> taskTable = new HashMap<>();
71
     static HashMap<String, Boolean> progressReport = new HashMap<>();
67
     static HashMap<String, Boolean> progressReport = new HashMap<>();
420
                 try {
416
                 try {
421
                     // For XMLHttpRequest, automatic response data storing strategy, when response
417
                     // For XMLHttpRequest, automatic response data storing strategy, when response
422
                     // data is considered as binary data, write it to file system
418
                     // data is considered as binary data, write it to file system
423
-                    if(isBlobResp && options.auto == true) {
419
+                    if(isBlobResp && options.auto) {
424
                         String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
420
                         String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
425
                         InputStream ins = resp.body().byteStream();
421
                         InputStream ins = resp.body().byteStream();
426
                         FileOutputStream os = new FileOutputStream(new File(dest));
422
                         FileOutputStream os = new FileOutputStream(new File(dest));
503
     }
499
     }
504
 
500
 
505
     /**
501
     /**
506
-     * Create response information object, conatins status code, headers, etc.
507
-     * @param resp
508
-     * @param isBlobResp
509
-     * @return
502
+     * Create response information object, contains status code, headers, etc.
503
+     * @param resp Response object
504
+     * @param isBlobResp If the response is binary data
505
+     * @return Get RCT bridge object contains response information.
510
      */
506
      */
511
     private WritableMap getResponseInfo(Response resp, boolean isBlobResp) {
507
     private WritableMap getResponseInfo(Response resp, boolean isBlobResp) {
512
         WritableMap info = Arguments.createMap();
508
         WritableMap info = Arguments.createMap();
543
     /**
539
     /**
544
      * Check if response data is binary data.
540
      * Check if response data is binary data.
545
      * @param resp OkHttp response.
541
      * @param resp OkHttp response.
546
-     * @return
542
+     * @return If the response data contains binary bytes
547
      */
543
      */
548
     private boolean isBlobResponse(Response resp) {
544
     private boolean isBlobResponse(Response resp) {
549
         Headers h = resp.headers();
545
         Headers h = resp.headers();

+ 1
- 3
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobUtils.java 查看文件

16
 
16
 
17
 import okhttp3.OkHttpClient;
17
 import okhttp3.OkHttpClient;
18
 
18
 
19
-/**
20
- * Created by wkh237 on 2016/7/11.
21
- */
19
+
22
 public class RNFetchBlobUtils {
20
 public class RNFetchBlobUtils {
23
 
21
 
24
     public static String getMD5(String input) {
22
     public static String getMD5(String input) {