You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/03/11 16:35:21 UTC

[10/13] cordova-plugin-file git commit: android: Add `listChildren()`: Java-consumable version of `readEntriesAtLocalURL()`

android: Add `listChildren()`: Java-consumable version of `readEntriesAtLocalURL()`


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/7051ad35
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/7051ad35
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/7051ad35

Branch: refs/heads/master
Commit: 7051ad35890bf37d17f18ea56d71d796e160fc0c
Parents: 356d334
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Mar 10 22:42:06 2015 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 11 11:35:08 2015 -0400

----------------------------------------------------------------------
 src/android/AssetFilesystem.java   | 14 +++++---------
 src/android/ContentFilesystem.java |  7 +++----
 src/android/Filesystem.java        | 13 ++++++++++++-
 src/android/LocalFilesystem.java   | 21 ++++++++++-----------
 4 files changed, 30 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7051ad35/src/android/AssetFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/AssetFilesystem.java b/src/android/AssetFilesystem.java
index 7a54e43..40968e0 100644
--- a/src/android/AssetFilesystem.java
+++ b/src/android/AssetFilesystem.java
@@ -97,27 +97,23 @@ public class AssetFilesystem extends Filesystem {
 
 
     @Override
-	public JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
-        String[] files;
+    public LocalFilesystemURL[] listChildren(LocalFilesystemURL inputURL) throws FileNotFoundException {
         String pathNoSlashes = inputURL.path.substring(1);
         if (pathNoSlashes.endsWith("/")) {
             pathNoSlashes = pathNoSlashes.substring(0, pathNoSlashes.length() - 1);
         }
 
+        String[] files;
         try {
             files = assetManager.list(pathNoSlashes);
         } catch (IOException e) {
             throw new FileNotFoundException();
         }
 
-        JSONArray entries = new JSONArray();
-        if (files != null) {
-            for (String file : files) {
-                Uri newNativeUri = nativeUriForFullPath(new File(inputURL.path, file).getPath());
-                entries.put(makeEntryForNativeUri(newNativeUri));
-            }
+        LocalFilesystemURL[] entries = new LocalFilesystemURL[files.length];
+        for (int i = 0; i < files.length; ++i) {
+            entries[i] = URLforFullPath(new File(inputURL.path, files[i]).getPath());
         }
-
         return entries;
 	}
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7051ad35/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 25c6489..eab0b03 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -112,11 +112,10 @@ public class ContentFilesystem extends Filesystem {
 		throw new NoModificationAllowedException("Cannot remove content url");
 	}
 
-	@Override
-	public JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL)
-			throws FileNotFoundException {
+    @Override
+    public LocalFilesystemURL[] listChildren(LocalFilesystemURL inputURL) throws FileNotFoundException {
         throw new UnsupportedOperationException("readEntriesAtLocalURL() not supported for content:. Use resolveLocalFileSystemURL instead.");
-	}
+    }
 
 	@Override
 	public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7051ad35/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 724976d..309c0b8 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -106,7 +106,18 @@ public abstract class Filesystem {
 
 	abstract boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) throws FileExistsException, NoModificationAllowedException;
 
-	abstract JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+	abstract LocalFilesystemURL[] listChildren(LocalFilesystemURL inputURL) throws FileNotFoundException;
+
+    public final JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
+        LocalFilesystemURL[] children = listChildren(inputURL);
+        JSONArray entries = new JSONArray();
+        if (children != null) {
+            for (LocalFilesystemURL url : children) {
+                entries.put(makeEntryForURL(url));
+            }
+        }
+        return entries;
+    }
 
 	abstract JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7051ad35/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 83c1384..93ba2b0 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -219,8 +219,8 @@ public class LocalFilesystem extends Filesystem {
         }
 	}
 
-	@Override
-	public JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
+    @Override
+    public LocalFilesystemURL[] listChildren(LocalFilesystemURL inputURL) throws FileNotFoundException {
         File fp = new File(filesystemPathForURL(inputURL));
 
         if (!fp.exists()) {
@@ -228,15 +228,14 @@ public class LocalFilesystem extends Filesystem {
             throw new FileNotFoundException();
         }
 
-        JSONArray entries = new JSONArray();
-
-        if (fp.isDirectory()) {
-            File[] files = fp.listFiles();
-            for (int i = 0; i < files.length; i++) {
-                if (files[i].canRead()) {
-                    entries.put(makeEntryForFile(files[i]));
-                }
-            }
+        File[] files = fp.listFiles();
+        if (files == null) {
+            // inputURL is a directory
+            return null;
+        }
+        LocalFilesystemURL[] entries = new LocalFilesystemURL[files.length];
+        for (int i = 0; i < files.length; i++) {
+            entries[i] = URLforFilesystemPath(files[i].getPath());
         }
 
         return entries;


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