@@ -70,7 +70,7 @@ static void writeFile(String path, String encoding, String data, final boolean a
7070
7171 // write data from a file
7272 if (encoding .equalsIgnoreCase (ReactNativeBlobUtilConst .DATA_ENCODE_URI )) {
73- String normalizedData = normalizePath (data );
73+ String normalizedData = ReactNativeBlobUtilUtils . normalizePath (data );
7474 File src = new File (normalizedData );
7575 if (!src .exists ()) {
7676 promise .reject ("ENOENT" , "No such file '" + path + "' " + "('" + normalizedData + "')" );
@@ -97,7 +97,7 @@ static void writeFile(String path, String encoding, String data, final boolean a
9797 }
9898 }
9999 } else {
100- byte [] bytes = stringToBytes (data , encoding );
100+ byte [] bytes = ReactNativeBlobUtilUtils . stringToBytes (data , encoding );
101101 FileOutputStream fout = new FileOutputStream (f , append );
102102 try {
103103 fout .write (bytes );
@@ -167,7 +167,7 @@ static void writeFile(String path, ReadableArray data, final boolean append, fin
167167 * @param promise JS promise
168168 */
169169 static void readFile (String path , String encoding , final Promise promise ) {
170- String resolved = normalizePath (path );
170+ String resolved = ReactNativeBlobUtilUtils . normalizePath (path );
171171 if (resolved != null )
172172 path = resolved ;
173173 try {
@@ -337,7 +337,7 @@ static String getTmpPath(String taskId) {
337337 * @param bufferSize Buffer size of read stream, default to 4096 (4095 when encode is `base64`)
338338 */
339339 void readStream (String path , String encoding , int bufferSize , int tick , final String streamId ) {
340- String resolved = normalizePath (path );
340+ String resolved = ReactNativeBlobUtilUtils . normalizePath (path );
341341 if (resolved != null )
342342 path = resolved ;
343343
@@ -480,7 +480,7 @@ void writeStream(String path, String encoding, boolean append, Callback callback
480480 static void writeChunk (String streamId , String data , Callback callback ) {
481481 ReactNativeBlobUtilFS fs = fileStreams .get (streamId );
482482 OutputStream stream = fs .writeStreamInstance ;
483- byte [] chunk = ReactNativeBlobUtilFS .stringToBytes (data , fs .encoding );
483+ byte [] chunk = ReactNativeBlobUtilUtils .stringToBytes (data , fs .encoding );
484484 try {
485485 stream .write (chunk );
486486 callback .invoke ();
@@ -537,7 +537,7 @@ static void closeStream(String streamId, Callback callback) {
537537 */
538538 static void unlink (String path , Callback callback ) {
539539 try {
540- String normalizedPath = normalizePath (path );
540+ String normalizedPath = ReactNativeBlobUtilUtils . normalizePath (path );
541541 ReactNativeBlobUtilFS .deleteRecursive (new File (normalizedPath ));
542542 callback .invoke (null , true );
543543 } catch (Exception err ) {
@@ -595,7 +595,7 @@ static void mkdir(String path, Promise promise) {
595595 * @param callback JS context callback
596596 */
597597 static void cp (String path , String dest , Callback callback ) {
598- path = normalizePath (path );
598+ path = ReactNativeBlobUtilUtils . normalizePath (path );
599599 InputStream in = null ;
600600 OutputStream out = null ;
601601 String message = "" ;
@@ -700,7 +700,7 @@ static void exists(String path, Callback callback) {
700700 callback .invoke (false , false );
701701 }
702702 } else {
703- path = normalizePath (path );
703+ path = ReactNativeBlobUtilUtils . normalizePath (path );
704704 if (path != null ) {
705705 boolean exist = new File (path ).exists ();
706706 boolean isDir = new File (path ).isDirectory ();
@@ -719,7 +719,7 @@ static void exists(String path, Callback callback) {
719719 */
720720 static void ls (String path , Promise promise ) {
721721 try {
722- path = normalizePath (path );
722+ path = ReactNativeBlobUtilUtils . normalizePath (path );
723723 File src = new File (path );
724724 if (!src .exists ()) {
725725 promise .reject ("ENOENT" , "No such file '" + path + "'" );
@@ -754,7 +754,7 @@ static void ls(String path, Promise promise) {
754754 */
755755 static void slice (String path , String dest , int start , int end , String encode , Promise promise ) {
756756 try {
757- path = normalizePath (path );
757+ path = ReactNativeBlobUtilUtils . normalizePath (path );
758758 File source = new File (path );
759759 if (source .isDirectory ()) {
760760 promise .reject ("EISDIR" , "Expecting a file but '" + path + "' is a directory" );
@@ -796,7 +796,7 @@ static void slice(String path, String dest, int start, int end, String encode, P
796796 }
797797
798798 static void lstat (String path , final Callback callback ) {
799- path = normalizePath (path );
799+ path = ReactNativeBlobUtilUtils . normalizePath (path );
800800
801801 new AsyncTask <String , Integer , Integer >() {
802802 @ Override
@@ -835,7 +835,7 @@ protected Integer doInBackground(String... args) {
835835 */
836836 static void stat (String path , Callback callback ) {
837837 try {
838- path = normalizePath (path );
838+ path = ReactNativeBlobUtilUtils . normalizePath (path );
839839 WritableMap result = statFile (path );
840840 if (result == null )
841841 callback .invoke ("failed to stat path `" + path + "` because it does not exist or it is not a folder" , null );
@@ -854,7 +854,7 @@ static void stat(String path, Callback callback) {
854854 */
855855 static WritableMap statFile (String path ) {
856856 try {
857- path = normalizePath (path );
857+ path = ReactNativeBlobUtilUtils . normalizePath (path );
858858 WritableMap stat = Arguments .createMap ();
859859 if (isAsset (path )) {
860860 String name = path .replace (ReactNativeBlobUtilConst .FILE_PREFIX_BUNDLE_ASSET , "" );
@@ -990,7 +990,7 @@ static void createFile(String path, String data, String encoding, Promise promis
990990 return ;
991991 }
992992 OutputStream ostream = new FileOutputStream (dest );
993- ostream .write (ReactNativeBlobUtilFS .stringToBytes (data , encoding ));
993+ ostream .write (ReactNativeBlobUtilUtils .stringToBytes (data , encoding ));
994994 }
995995 promise .resolve (path );
996996 } catch (Exception err ) {
@@ -1085,25 +1085,6 @@ protected Integer doInBackground(ReadableArray... paths) {
10851085 task .execute (paths );
10861086 }
10871087
1088- /**
1089- * String to byte converter method
1090- *
1091- * @param data Raw data in string format
1092- * @param encoding Decoder name
1093- * @return Converted data byte array
1094- */
1095- private static byte [] stringToBytes (String data , String encoding ) {
1096- if (encoding .equalsIgnoreCase ("ascii" )) {
1097- return data .getBytes (Charset .forName ("US-ASCII" ));
1098- } else if (encoding .toLowerCase ().contains ("base64" )) {
1099- return Base64 .decode (data , Base64 .NO_WRAP );
1100-
1101- } else if (encoding .equalsIgnoreCase ("utf8" )) {
1102- return data .getBytes (Charset .forName ("UTF-8" ));
1103- }
1104- return data .getBytes (Charset .forName ("US-ASCII" ));
1105- }
1106-
11071088 /**
11081089 * Private method for emit read stream event.
11091090 *
@@ -1174,26 +1155,4 @@ static boolean isAsset(String path) {
11741155 return path != null && path .startsWith (ReactNativeBlobUtilConst .FILE_PREFIX_BUNDLE_ASSET );
11751156 }
11761157
1177- /**
1178- * Normalize the path, remove URI scheme (xxx://) so that we can handle it.
1179- *
1180- * @param path URI string.
1181- * @return Normalized string
1182- */
1183- static String normalizePath (String path ) {
1184- if (path == null )
1185- return null ;
1186- if (!path .matches ("\\ w+\\ :.*" ))
1187- return path ;
1188- if (path .startsWith ("file://" )) {
1189- return path .replace ("file://" , "" );
1190- }
1191-
1192- Uri uri = Uri .parse (path );
1193- if (path .startsWith (ReactNativeBlobUtilConst .FILE_PREFIX_BUNDLE_ASSET )) {
1194- return path ;
1195- } else
1196- return PathResolver .getRealPathFromURI (ReactNativeBlobUtil .RCTContext , uri );
1197- }
1198-
11991158}
0 commit comments