cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/2] cordova-plugin-file git commit: android: Simplify code a bit by making makeEntryForPath not throw JSONException
Date Fri, 09 Jan 2015 02:25:58 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master cd45e67fe -> 25c714b84


android: Simplify code a bit by making makeEntryForPath not throw JSONException


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/33330ca6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/33330ca6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/33330ca6

Branch: refs/heads/master
Commit: 33330ca686b69138422d133f8131ea683c03456a
Parents: cd45e67
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Jan 8 21:08:33 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Jan 8 21:08:33 2015 -0500

----------------------------------------------------------------------
 src/android/ContentFilesystem.java | 14 +++-------
 src/android/Filesystem.java        | 48 ++++++++++++++++++---------------
 src/android/LocalFilesystem.java   | 11 ++------
 3 files changed, 31 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/33330ca6/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 8780649..9802d1c 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -73,11 +73,7 @@ public class ContentFilesystem extends Filesystem {
 	@Override
 	public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
 	    if ("/".equals(inputURL.fullPath)) {
-            try {
-                return LocalFilesystem.makeEntryForURL(inputURL, true, inputURL.URL.toString());
-            } catch (JSONException e) {
-                throw new IOException();
-            }
+            return LocalFilesystem.makeEntryForURL(inputURL, true, inputURL.URL.toString());
 	    }
 
 		// Get the cursor to validate that the file exists
@@ -97,11 +93,7 @@ public class ContentFilesystem extends Filesystem {
 		} else {
 			filePath = "file://" + filePath;
 		}
-		try {
-			return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, false /*fp.isDirectory()*/,
filePath);
-		} catch (JSONException e) {
-			throw new IOException();
-		}
+        return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, false /*fp.isDirectory()*/,
filePath);
 	}
 	
     @Override
@@ -324,4 +316,4 @@ public class ContentFilesystem extends Filesystem {
 		OutputStream os = resourceApi.openOutputStream(inputURL.URL);
 		return os;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/33330ca6/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index bbdeb0b..ef07848 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -37,31 +37,35 @@ public abstract class Filesystem {
 		public void handleData(InputStream inputStream, String contentType) throws IOException;
 	}
 
-	public static JSONObject makeEntryForPath(String path, String fsName, Boolean isDir, String
nativeURL)
-			throws JSONException {
-        JSONObject entry = new JSONObject();
-
-        int end = path.endsWith("/") ? 1 : 0;
-        String[] parts = path.substring(0,path.length()-end).split("/+");
-        String fileName = parts[parts.length-1];
-        entry.put("isFile", !isDir);
-        entry.put("isDirectory", isDir);
-        entry.put("name", fileName);
-        entry.put("fullPath", path);
-        // The file system can't be specified, as it would lead to an infinite loop,
-        // but the filesystem name can be.
-        entry.put("filesystemName", fsName);
-        // Backwards compatibility
-        entry.put("filesystem", "temporary".equals(fsName) ? 0 : 1);
-
-        if (isDir && !nativeURL.endsWith("/")) {
-            nativeURL += "/";
+	public static JSONObject makeEntryForPath(String path, String fsName, Boolean isDir, String
nativeURL) {
+        try {
+            JSONObject entry = new JSONObject();
+
+            int end = path.endsWith("/") ? 1 : 0;
+            String[] parts = path.substring(0, path.length() - end).split("/+");
+            String fileName = parts[parts.length - 1];
+            entry.put("isFile", !isDir);
+            entry.put("isDirectory", isDir);
+            entry.put("name", fileName);
+            entry.put("fullPath", path);
+            // The file system can't be specified, as it would lead to an infinite loop,
+            // but the filesystem name can be.
+            entry.put("filesystemName", fsName);
+            // Backwards compatibility
+            entry.put("filesystem", "temporary".equals(fsName) ? 0 : 1);
+
+            if (isDir && !nativeURL.endsWith("/")) {
+                nativeURL += "/";
+            }
+            entry.put("nativeURL", nativeURL);
+            return entry;
+        } catch (JSONException e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
         }
-    	entry.put("nativeURL", nativeURL);
-        return entry;
     }
 
-    public static JSONObject makeEntryForURL(LocalFilesystemURL inputURL, Boolean isDir,
String nativeURL) throws JSONException {
+    public static JSONObject makeEntryForURL(LocalFilesystemURL inputURL, Boolean isDir,
String nativeURL) {
         return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, isDir, nativeURL);
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/33330ca6/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 9bbd7f8..1a975c1 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -143,11 +143,7 @@ public class LocalFilesystem extends Filesystem {
       if (!fp.canRead()) {
           throw new IOException();
       }
-      try {
-          return LocalFilesystem.makeEntryForURL(inputURL, fp.isDirectory(),  Uri.fromFile(fp).toString());
-      } catch (JSONException e) {
-    	  throw new IOException();
-      }
+      return LocalFilesystem.makeEntryForURL(inputURL, fp.isDirectory(),  Uri.fromFile(fp).toString());
 	}
 
 	@Override
@@ -259,10 +255,7 @@ public class LocalFilesystem extends Filesystem {
             File[] files = fp.listFiles();
             for (int i = 0; i < files.length; i++) {
                 if (files[i].canRead()) {
-                    try {
-						entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()),
inputURL.filesystemName, files[i].isDirectory(), Uri.fromFile(files[i]).toString()));
-					} catch (JSONException e) {
-					}
+                    entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()),
inputURL.filesystemName, files[i].isDirectory(), Uri.fromFile(files[i]).toString()));
                 }
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message