You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/12/13 17:17:57 UTC
[01/15] git commit: CB-5532 Fix
Updated Branches:
refs/heads/android-file [created] a83ae5689
CB-5532 Fix
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/2685ae6d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/2685ae6d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/2685ae6d
Branch: refs/heads/android-file
Commit: 2685ae6dfa605da0a692eb5e60ccee2c12a250e2
Parents: 6b0ab74
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Dec 11 09:57:32 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:32 2013 -0500
----------------------------------------------------------------------
www/FileWriter.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2685ae6d/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 7b3a007..786e994 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -118,7 +118,7 @@ FileWriter.prototype.write = function(data) {
// Mark data type for safer transport over the binary bridge
isBinary = supportsBinary && (data instanceof ArrayBuffer);
- if (isBinary) {
+ if (isBinary && ['windowsphone', 'windows8'].indexOf(cordova.platformId) >= 0) {
// create a plain array, using the keys from the Uint8Array view so that we can serialize it
data = Array.apply(null, new Uint8Array(data));
}
[15/15] git commit: Android: Clean up unclosed file objects
Posted by ia...@apache.org.
Android: Clean up unclosed file objects
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/5df7f190
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5df7f190
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5df7f190
Branch: refs/heads/android-file
Commit: 5df7f190fab683f7629ba01840731e92e338f8ea
Parents: 9125371
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Dec 2 15:53:43 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 10:00:11 2013 -0500
----------------------------------------------------------------------
src/android/LocalFilesystem.java | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5df7f190/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index adb3ef6..be1d2d1 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -537,19 +537,20 @@ public class LocalFilesystem implements Filesystem {
String contentType;
File file = new File(this.filesystemPathForURL(inputURL));
- InputStream inputStream = new FileInputStream(file);
-
contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
+
+ InputStream inputStream = new FileInputStream(file);
int numBytesRead = 0;
-
- if (start > 0) {
- inputStream.skip(start);
- }
-
- while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
- numBytesToRead -= numBytesRead;
+ try {
+ if (start > 0) {
+ inputStream.skip(start);
+ }
+ while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
+ numBytesToRead -= numBytesRead;
+ }
+ } finally {
+ inputStream.close();
}
- inputStream.close();
readFileCallback.handleData(bytes, contentType);
}
@@ -572,12 +573,16 @@ public class LocalFilesystem implements Filesystem {
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
try
{
+ byte buff[] = new byte[rawData.length];
FileOutputStream out = new FileOutputStream(this.filesystemPathForURL(inputURL), append);
- byte buff[] = new byte[rawData.length];
- in.read(buff, 0, buff.length);
- out.write(buff, 0, rawData.length);
- out.flush();
- out.close();
+ try {
+ in.read(buff, 0, buff.length);
+ out.write(buff, 0, rawData.length);
+ out.flush();
+ } finally {
+ // Always close the output
+ out.close();
+ }
}
catch (NullPointerException e)
{
[10/15] git commit: CB-5407: Move readdir methods into FS modules
Posted by ia...@apache.org.
CB-5407: Move readdir methods into FS modules
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/03fcd128
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/03fcd128
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/03fcd128
Branch: refs/heads/android-file
Commit: 03fcd1280e068c7ec8064b26ec6739c49de9567d
Parents: 21b73d6
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Nov 27 14:35:55 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 7 +++++++
src/android/FileUtils.java | 33 ++++++++++++-----------------
src/android/Filesystem.java | 4 ++++
src/android/LocalFilesystem.java | 37 +++++++++++++++++++++++++++++++--
4 files changed, 59 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/03fcd128/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 7325ac6..8fef685 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -5,6 +5,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.cordova.CordovaInterface;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -64,5 +65,11 @@ public class ContentFilesystem implements Filesystem {
throws NoModificationAllowedException {
throw new NoModificationAllowedException("Cannot remove content url");
}
+ @Override
+ public JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL)
+ throws FileNotFoundException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/03fcd128/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index a373d50..01ce90b 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -337,7 +337,7 @@ public class FileUtils extends CordovaPlugin {
else if (action.equals("readEntries")) {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() throws FileNotFoundException, JSONException {
+ public void run() throws FileNotFoundException, JSONException, MalformedURLException {
JSONArray entries = readEntries(fname);
callbackContext.success(entries);
}
@@ -433,27 +433,20 @@ public class FileUtils extends CordovaPlugin {
* @return a JSONArray containing JSONObjects that represent Entry objects.
* @throws FileNotFoundException if the directory is not found.
* @throws JSONException
+ * @throws MalformedURLException
*/
- private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException {
- File fp = createFileObject(fileName);
-
- if (!fp.exists()) {
- // The directory we are listing doesn't exist so we should fail.
- 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(getEntry(files[i]));
- }
- }
+ private JSONArray readEntries(String baseURLstr) throws FileNotFoundException, JSONException, MalformedURLException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.readEntriesAtLocalURL(inputURL);
+
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
-
- return entries;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/03fcd128/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index a4730ba..4abd403 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -1,7 +1,9 @@
package org.apache.cordova.file;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -16,4 +18,6 @@ public interface Filesystem {
boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) throws FileExistsException, NoModificationAllowedException;
+ JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/03fcd128/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index aca9d15..7d3aacb 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -36,7 +37,6 @@ public class LocalFilesystem implements Filesystem {
int end = path.endsWith("/") ? 1 : 0;
String[] parts = path.substring(0,path.length()-end).split("/");
String name = parts[parts.length-1];
- Log.d("FILEDEBUG", name);
entry.put("isFile", !isDir);
entry.put("isDirectory", isDir);
entry.put("name", name);
@@ -65,7 +65,7 @@ public class LocalFilesystem implements Filesystem {
entry.put("isFile", fp.isFile());
entry.put("isDirectory", fp.isDirectory());
entry.put("name", fp.getName());
- entry.put("fullPath", "file://" + fp.getAbsolutePath());
+ entry.put("fullPath", inputURL.fullPath);
// The file system can't be specified, as it would lead to an infinite loop.
// But we can specify the type of FS, and the rest can be reconstructed in JS.
entry.put("filesystem", inputURL.filesystemType);
@@ -181,4 +181,37 @@ public class LocalFilesystem implements Filesystem {
}
}
+ @Override
+ public JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
+ File fp = new File(filesystemPathForURL(inputURL));
+
+ if (!fp.exists()) {
+ // The directory we are listing doesn't exist so we should fail.
+ 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()) {
+ try {
+ entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()), inputURL.filesystemType, files[i].isDirectory()));
+ } catch (JSONException e) {
+ }
+ }
+ }
+ }
+
+ return entries;
+ }
+
+ private String fullPathForFilesystemPath(String absolutePath) {
+ if (absolutePath != null && absolutePath.startsWith(this.fsRoot)) {
+ return absolutePath.substring(this.fsRoot.length());
+ }
+ return null;
+ }
+
}
[14/15] git commit: Android: Updates to allow FileTransfer to
continue to work
Posted by ia...@apache.org.
Android: Updates to allow FileTransfer to continue to work
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/d796fecd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/d796fecd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/d796fecd
Branch: refs/heads/android-file
Commit: d796fecd9bc9119590da2892b9dfff2cd32eeb56
Parents: 5df7f19
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Dec 2 15:54:11 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 10:00:11 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 5 +++
src/android/FileUtils.java | 58 ++++++++++++++++++++++++---------
src/android/Filesystem.java | 3 ++
src/android/LocalFilesystem.java | 23 ++++++++-----
4 files changed, 64 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d796fecd/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 17bead8..4e5175b 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -108,4 +108,9 @@ public class ContentFilesystem implements Filesystem {
throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
}
+ @Override
+ public String filesystemPathForURL(LocalFilesystemURL url) {
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d796fecd/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 00483bc..1f345fe 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -18,6 +18,7 @@
*/
package org.apache.cordova.file;
+import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Base64;
@@ -65,6 +66,9 @@ public class FileUtils extends CordovaPlugin {
public static int PERSISTENT = 1;
public static int RESOURCE = 2;
public static int APPLICATION = 3;
+
+ // This field exists only to support getEntry, below, which has been deprecated
+ private static FileUtils filePlugin;
private interface FileOp {
void run( ) throws Exception;
@@ -94,6 +98,11 @@ public class FileUtils extends CordovaPlugin {
this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
this.filesystems.add(new ContentFilesystem(cordova));
+
+ // Initialize static plugin reference for deprecated getEntry method
+ if (filePlugin == null) {
+ filePlugin = this;
+ }
}
public Filesystem filesystemForURL(LocalFilesystemURL localURL) {
@@ -104,6 +113,20 @@ public class FileUtils extends CordovaPlugin {
}
}
+ @Override
+ public Uri remapUri(Uri uri) {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(uri);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ return null;
+ }
+ return Uri.parse("file:///" + fs.filesystemPathForURL(inputURL));
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
/**
* Executes the request and returns whether the action was valid.
*
@@ -644,7 +667,10 @@ public class FileUtils extends CordovaPlugin {
}
/**
- * Returns a JSON object representing the given File.
+ * Returns a JSON object representing the given File. Deprecated, as this is only used by
+ * FileTransfer, and because it is a static method that should really be an instance method,
+ * since it depends on the actual filesystem roots in use. Internal APIs should be modified
+ * to use URLs instead of raw FS paths wherever possible, when interfacing with this plugin.
*
* @param file the File to convert
* @return a JSON representation of the given File
@@ -652,22 +678,22 @@ public class FileUtils extends CordovaPlugin {
*/
@Deprecated
public static JSONObject getEntry(File file) throws JSONException {
- String path = file.getAbsolutePath();
- Boolean isDir = file.isDirectory();
- JSONObject entry = new JSONObject();
-
- int end = path.endsWith("/") ? 1 : 0;
- String[] parts = path.substring(0,path.length()-end).split("/",1);
- String name = parts[parts.length-1];
- entry.put("isFile", !isDir);
- entry.put("isDirectory", isDir);
- entry.put("name", name);
- entry.put("fullPath", path);
- // The file system can't be specified, as it would lead to an infinite loop,
- // but the filesystem type can
- entry.put("filesystem", 0);
+ JSONObject entry;
- return entry;
+ if (filePlugin != null) {
+ LocalFilesystem fs;
+ fs = (LocalFilesystem) filePlugin.filesystems.get(0);
+ entry = fs.makeEntryForFile(file, 0);
+ if (entry != null) {
+ return entry;
+ }
+ fs = (LocalFilesystem) filePlugin.filesystems.get(1);
+ entry = fs.makeEntryForFile(file, 1);
+ if (entry != null) {
+ return entry;
+ }
+ }
+ return null;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d796fecd/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 6955520..57e1794 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -37,4 +37,7 @@ public interface Filesystem {
long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
throws IOException, NoModificationAllowedException;
+ // This method should return null if filesystem urls cannot be mapped to paths
+ String filesystemPathForURL(LocalFilesystemURL url);
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d796fecd/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index be1d2d1..755a802 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -30,6 +30,7 @@ public class LocalFilesystem implements Filesystem {
this.cordova = cordova;
}
+ @Override
public String filesystemPathForURL(LocalFilesystemURL url) {
String path = this.fsRoot + url.fullPath;
if (path.endsWith("/")) {
@@ -37,7 +38,14 @@ public class LocalFilesystem implements Filesystem {
}
return path;
}
-
+
+ private String fullPathForFilesystemPath(String absolutePath) {
+ if (absolutePath != null && absolutePath.startsWith(this.fsRoot)) {
+ return absolutePath.substring(this.fsRoot.length());
+ }
+ return null;
+ }
+
public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
JSONObject entry = new JSONObject();
@@ -57,7 +65,11 @@ public class LocalFilesystem implements Filesystem {
}
public JSONObject makeEntryForFile(File file, int fsType) throws JSONException {
- return makeEntryForPath(this.fullPathForFilesystemPath(file.getAbsolutePath()), fsType, file.isDirectory());
+ String path = this.fullPathForFilesystemPath(file.getAbsolutePath());
+ if (path != null) {
+ return makeEntryForPath(path, fsType, file.isDirectory());
+ }
+ return null;
}
@Override
@@ -199,13 +211,6 @@ public class LocalFilesystem implements Filesystem {
return entries;
}
- private String fullPathForFilesystemPath(String absolutePath) {
- if (absolutePath != null && absolutePath.startsWith(this.fsRoot)) {
- return absolutePath.substring(this.fsRoot.length());
- }
- return null;
- }
-
@Override
public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
File file = new File(filesystemPathForURL(inputURL));
[06/15] git commit: CB-5407: Start refactoring android code: Modular
filesystems, rfs, rlfsurl
Posted by ia...@apache.org.
CB-5407: Start refactoring android code: Modular filesystems, rfs, rlfsurl
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/96d632fc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/96d632fc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/96d632fc
Branch: refs/heads/android-file
Commit: 96d632fc349bae32643aba2830f7cf1b4d8b4f52
Parents: abf2c05
Author: Ian Clelland <ic...@chromium.org>
Authored: Sun Nov 24 22:47:19 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 53 ++++++++++++++
src/android/FileUtils.java | 121 ++++++++++++++++++-------------
src/android/Filesystem.java | 11 +++
src/android/LocalFilesystem.java | 50 +++++++++++++
src/android/LocalFilesystemURL.java | 54 ++++++++++++++
5 files changed, 238 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/96d632fc/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
new file mode 100644
index 0000000..bef40a3
--- /dev/null
+++ b/src/android/ContentFilesystem.java
@@ -0,0 +1,53 @@
+package org.apache.cordova.file;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.apache.cordova.CordovaInterface;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.database.Cursor;
+import android.provider.MediaStore;
+
+public class ContentFilesystem implements Filesystem {
+
+ private CordovaInterface cordova;
+
+ public ContentFilesystem(CordovaInterface cordova) {
+ this.cordova = cordova;
+ }
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
+ File fp = null;
+
+ Cursor cursor = this.cordova.getActivity().managedQuery(inputURL.URL, new String[] { MediaStore.Images.Media.DATA }, null, null, null);
+ // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
+ int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
+ cursor.moveToFirst();
+ fp = new File(cursor.getString(column_index));
+
+ if (!fp.exists()) {
+ throw new FileNotFoundException();
+ }
+ if (!fp.canRead()) {
+ throw new IOException();
+ }
+ try {
+ JSONObject entry = new JSONObject();
+ entry.put("isFile", fp.isFile());
+ entry.put("isDirectory", fp.isDirectory());
+ entry.put("name", fp.getName());
+ entry.put("fullPath", "file://" + fp.getAbsolutePath());
+ // The file system can't be specified, as it would lead to an infinite loop.
+ entry.put("filesystem", FileUtils.APPLICATION);
+ return entry;
+ } catch (JSONException e) {
+ throw new IOException();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/96d632fc/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 29026f0..473af3e 100755
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -18,15 +18,15 @@
*/
package org.apache.cordova.file;
-import android.database.Cursor;
-import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
@@ -42,9 +42,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
-import java.net.URL;
import java.net.URLDecoder;
import java.nio.channels.FileChannel;
+import java.util.ArrayList;
/**
* This class provides SD card file and directory services to JavaScript.
@@ -75,7 +75,41 @@ public class FileUtils extends CordovaPlugin {
private interface FileOp {
void run( ) throws Exception;
}
-
+
+ private ArrayList<Filesystem> filesystems;
+
+ @Override
+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+ super.initialize(cordova, webView);
+ this.filesystems = new ArrayList<Filesystem>();
+
+ File fp;
+ String tempRoot;
+ String persistentRoot;
+ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
+ tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
+ "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/";
+ } else {
+ persistentRoot = "/data/data/" + cordova.getActivity().getPackageName();
+ tempRoot = "/data/data/" + cordova.getActivity().getPackageName() + "/cache/";
+ }
+ // Create the cache dir if it doesn't exist.
+ fp = new File(tempRoot);
+ fp.mkdirs();
+ this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
+ this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
+ this.filesystems.add(new ContentFilesystem(cordova));
+ }
+
+ public Filesystem filesystemForURL(LocalFilesystemURL localURL) {
+ try {
+ return this.filesystems.get(localURL.filesystemType);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
/**
* Executes the request and returns whether the action was valid.
*
@@ -377,45 +411,21 @@ public class FileUtils extends CordovaPlugin {
* @throws IOException if the user can't read the file
* @throws JSONException
*/
- @SuppressWarnings("deprecation")
private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
String decoded = URLDecoder.decode(url, "UTF-8");
- File fp = null;
-
- // Handle the special case where you get an Android content:// uri.
- if (decoded.startsWith("content:")) {
- Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
- // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
- int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
- cursor.moveToFirst();
- fp = new File(cursor.getString(column_index));
- } else {
- // Test to see if this is a valid URL first
- @SuppressWarnings("unused")
- URL testUrl = new URL(decoded);
-
- if (decoded.startsWith("file://")) {
- int questionMark = decoded.indexOf("?");
- if (questionMark < 0) {
- fp = new File(decoded.substring(7, decoded.length()));
- } else {
- fp = new File(decoded.substring(7, questionMark));
- }
- } else {
- fp = new File(decoded);
- }
- }
-
- if (!fp.exists()) {
- throw new FileNotFoundException();
- }
- if (!fp.canRead()) {
- throw new IOException();
- }
- return getEntry(fp);
- }
-
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(decoded);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
+ }
+ return fs.getEntryForLocalURL(inputURL);
+ } catch (IllegalArgumentException e) {
+ throw new IOException();
+ }
+ }
+
/**
* Read the list of files from this directory.
*
@@ -1001,10 +1011,27 @@ public class FileUtils extends CordovaPlugin {
else {
throw new IOException("No filesystem of type requested");
}
-
+ fs.put("root", makeEntryForPath("/", type, true));
return fs;
}
+ public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
+ JSONObject entry = new JSONObject();
+
+ int end = path.endsWith("/") ? 1 : 0;
+ String[] parts = path.substring(0,path.length()-end).split("/",1);
+ String name = parts[parts.length-1];
+ entry.put("isFile", !isDir);
+ entry.put("isDirectory", isDir);
+ entry.put("name", name);
+ entry.put("fullPath", path);
+ // The file system can't be specified, as it would lead to an infinite loop,
+ // but the filesystem type can
+ entry.put("filesystem", fsType);
+
+ return entry;
+
+ }
/**
* Returns a JSON object representing the given File.
*
@@ -1012,17 +1039,9 @@ public class FileUtils extends CordovaPlugin {
* @return a JSON representation of the given File
* @throws JSONException
*/
+ @Deprecated
public static JSONObject getEntry(File file) throws JSONException {
- JSONObject entry = new JSONObject();
-
- entry.put("isFile", file.isFile());
- entry.put("isDirectory", file.isDirectory());
- entry.put("name", file.getName());
- entry.put("fullPath", "file://" + file.getAbsolutePath());
- // The file system can't be specified, as it would lead to an infinite loop.
- // entry.put("filesystem", null);
-
- return entry;
+ return makeEntryForPath(file.getAbsolutePath(), 0, file.isDirectory());
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/96d632fc/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
new file mode 100644
index 0000000..1879ad0
--- /dev/null
+++ b/src/android/Filesystem.java
@@ -0,0 +1,11 @@
+package org.apache.cordova.file;
+
+import java.io.IOException;
+
+import org.json.JSONObject;
+
+public interface Filesystem {
+
+ JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/96d632fc/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
new file mode 100644
index 0000000..c005867
--- /dev/null
+++ b/src/android/LocalFilesystem.java
@@ -0,0 +1,50 @@
+package org.apache.cordova.file;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.util.Base64;
+
+public class LocalFilesystem implements Filesystem {
+
+ private String name;
+ private String fsRoot;
+ private CordovaInterface cordova;
+
+ public LocalFilesystem(CordovaInterface cordova, String name, String fsRoot) {
+ this.name = name;
+ this.fsRoot = fsRoot;
+ this.cordova = cordova;
+ }
+
+ @Override
+ public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
+ File fp = null;
+ fp = new File(this.fsRoot + inputURL.fullPath); //TODO: Proper fs.join
+
+ if (!fp.exists()) {
+ throw new FileNotFoundException();
+ }
+ if (!fp.canRead()) {
+ throw new IOException();
+ }
+ try {
+ JSONObject entry = new JSONObject();
+ entry.put("isFile", fp.isFile());
+ entry.put("isDirectory", fp.isDirectory());
+ entry.put("name", fp.getName());
+ entry.put("fullPath", "file://" + fp.getAbsolutePath());
+ // The file system can't be specified, as it would lead to an infinite loop.
+ // But we can specify the type of FS, and the rest can be reconstructed in JS.
+ entry.put("filesystem", inputURL.filesystemType);
+ return entry;
+ } catch (JSONException e) {
+ throw new IOException();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/96d632fc/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
new file mode 100644
index 0000000..0dc547e
--- /dev/null
+++ b/src/android/LocalFilesystemURL.java
@@ -0,0 +1,54 @@
+package org.apache.cordova.file;
+
+import android.net.Uri;
+
+public class LocalFilesystemURL {
+ public static final int TEMPORARY = 0;
+ public static final int PERSISTENT = 1;
+
+ Uri URL;
+ int filesystemType;
+ String fullPath;
+
+ public LocalFilesystemURL(Uri URL) {
+ this.URL = URL;
+ this.filesystemType = this.filesystemTypeForLocalURL(URL);
+ this.fullPath = this.fullPathForLocalURL(URL);
+ }
+
+ private String fullPathForLocalURL(Uri URL) {
+ int fsType = this.filesystemTypeForLocalURL(URL);
+ if (fsType == FileUtils.TEMPORARY) {
+ return URL.getPath().substring(10);
+ }
+ if (fsType == FileUtils.PERSISTENT) {
+ return URL.getPath().substring(11);
+ }
+ if (fsType == FileUtils.APPLICATION) {
+ return URL.getPath();
+ }
+ return null;
+ }
+
+ private int filesystemTypeForLocalURL(Uri URL) {
+ if ("filesystem".equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
+ String path = URL.getPath();
+ if (path != null) {
+ if (path.startsWith("/temporary")) {
+ return FileUtils.TEMPORARY;
+ } else if (path.startsWith("/persistent")) {
+ return FileUtils.PERSISTENT;
+ }
+ }
+ } else if ("content".equals(URL.getScheme())) {
+ return FileUtils.APPLICATION;
+ }
+ return -1;
+ }
+
+ public LocalFilesystemURL(String strURL) {
+ this(Uri.parse(strURL));
+ }
+
+
+}
[13/15] git commit: Plugin.xml fix
Posted by ia...@apache.org.
Plugin.xml fix
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/a83ae568
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/a83ae568
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/a83ae568
Branch: refs/heads/android-file
Commit: a83ae5689ec11bdd9fde82df204af10a7b047519
Parents: d796fec
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Dec 4 08:25:37 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 10:00:11 2013 -0500
----------------------------------------------------------------------
plugin.xml | 10 ++++++++++
1 file changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a83ae568/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 3621c16..dba4dae 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -102,6 +102,16 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<source-file src="src/android/FileUtils.java" target-dir="src/org/apache/cordova/file" />
<source-file src="src/android/FileHelper.java" target-dir="src/org/apache/cordova/file" />
<source-file src="src/android/DirectoryManager.java" target-dir="src/org/apache/cordova/file" />
+ <source-file src="src/android/LocalFilesystemURL.java" target-dir="src/org/apache/cordova/file" />
+ <source-file src="src/android/Filesystem.java" target-dir="src/org/apache/cordova/file" />
+ <source-file src="src/android/LocalFilesystem.java" target-dir="src/org/apache/cordova/file" />
+ <source-file src="src/android/ContentFilesystem.java" target-dir="src/org/apache/cordova/file" />
+ <source-file src="src/android/ReadFileCallback.java" target-dir="src/org/apache/cordova/file" />
+
+ <!-- android specific file apis -->
+ <js-module src="www/android/FileSystem.js" name="androidFileSystem">
+ <merges target="window.FileSystem" />
+ </js-module>
</platform>
<!-- amazon-fireos -->
[05/15] git commit: CB-5407: Move copy/move methods into FS modules
Posted by ia...@apache.org.
CB-5407: Move copy/move methods into FS modules
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/1a6c80b0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/1a6c80b0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/1a6c80b0
Branch: refs/heads/android-file
Commit: 1a6c80b02db183540e8fd17ed503901c0eae2dd6
Parents: afee8d8
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Nov 28 11:11:10 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 8 +
src/android/FileUtils.java | 289 ++-----------------------------
src/android/Filesystem.java | 3 +
src/android/LocalFilesystem.java | 297 ++++++++++++++++++++++++++++++++
4 files changed, 320 insertions(+), 277 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/1a6c80b0/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 3b4e4c3..6071870 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -83,5 +83,13 @@ public class ContentFilesystem implements Filesystem {
// Can probably use same impl as LFS
return null;
}
+ @Override
+ public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
+ Filesystem srcFs, LocalFilesystemURL srcURL, boolean move)
+ throws IOException, InvalidModificationException, JSONException,
+ NoModificationAllowedException, FileExistsException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/1a6c80b0/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 8e3bea6..364e3d4 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -465,267 +465,24 @@ public class FileUtils extends CordovaPlugin {
* @throws JSONException
* @throws FileExistsException
*/
- private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
- String newFileName = FileHelper.getRealPath(fileName, cordova);
- newParent = FileHelper.getRealPath(newParent, cordova);
-
- // Check for invalid file name
- if (newName != null && newName.contains(":")) {
- throw new EncodingException("Bad file name");
- }
-
- File source = new File(newFileName);
-
- if (!source.exists()) {
- // The file/directory we are copying doesn't exist so we should fail.
- throw new FileNotFoundException("The source does not exist");
- }
-
- File destinationDir = new File(newParent);
- if (!destinationDir.exists()) {
- // The destination does not exist so we should fail.
- throw new FileNotFoundException("The source does not exist");
- }
-
- // Figure out where we should be copying to
- File destination = createDestination(newName, source, destinationDir);
-
- //Log.d(LOG_TAG, "Source: " + source.getAbsolutePath());
- //Log.d(LOG_TAG, "Destin: " + destination.getAbsolutePath());
-
- // Check to see if source and destination are the same file
- if (source.getAbsolutePath().equals(destination.getAbsolutePath())) {
- throw new InvalidModificationException("Can't copy a file onto itself");
- }
-
- if (source.isDirectory()) {
- if (move) {
- return moveDirectory(source, destination);
- } else {
- return copyDirectory(source, destination);
- }
- } else {
- if (move) {
- JSONObject newFileEntry = moveFile(source, destination);
-
- // If we've moved a file given its content URI, we need to clean up.
- if (fileName.startsWith("content://")) {
- notifyDelete(fileName);
- }
-
- return newFileEntry;
- } else {
- return copyFile(source, destination);
- }
- }
- }
-
- /**
- * Creates the destination File object based on name passed in
- *
- * @param newName for the file directory to be called, if null use existing file name
- * @param fp represents the source file
- * @param destination represents the destination file
- * @return a File object that represents the destination
- */
- private File createDestination(String newName, File fp, File destination) {
- File destFile = null;
-
- // I know this looks weird but it is to work around a JSON bug.
- if ("null".equals(newName) || "".equals(newName)) {
- newName = null;
- }
-
- if (newName != null) {
- destFile = new File(destination.getAbsolutePath() + File.separator + newName);
- } else {
- destFile = new File(destination.getAbsolutePath() + File.separator + fp.getName());
- }
- return destFile;
- }
-
- /**
- * Copy a file
- *
- * @param srcFile file to be copied
- * @param destFile destination to be copied to
- * @return a FileEntry object
- * @throws IOException
- * @throws InvalidModificationException
- * @throws JSONException
- */
- private JSONObject copyFile(File srcFile, File destFile) throws IOException, InvalidModificationException, JSONException {
- // Renaming a file to an existing directory should fail
- if (destFile.exists() && destFile.isDirectory()) {
- throw new InvalidModificationException("Can't rename a file to a directory");
- }
-
- copyAction(srcFile, destFile);
-
- return getEntry(destFile);
- }
-
- /**
- * Moved this code into it's own method so moveTo could use it when the move is across file systems
- */
- private void copyAction(File srcFile, File destFile)
- throws FileNotFoundException, IOException {
- FileInputStream istream = new FileInputStream(srcFile);
- FileOutputStream ostream = new FileOutputStream(destFile);
- FileChannel input = istream.getChannel();
- FileChannel output = ostream.getChannel();
-
- try {
- input.transferTo(0, input.size(), output);
- } finally {
- istream.close();
- ostream.close();
- input.close();
- output.close();
- }
- }
-
- /**
- * Copy a directory
- *
- * @param srcDir directory to be copied
- * @param destinationDir destination to be copied to
- * @return a DirectoryEntry object
- * @throws JSONException
- * @throws IOException
- * @throws NoModificationAllowedException
- * @throws InvalidModificationException
- */
- private JSONObject copyDirectory(File srcDir, File destinationDir) throws JSONException, IOException, NoModificationAllowedException, InvalidModificationException {
- // Renaming a file to an existing directory should fail
- if (destinationDir.exists() && destinationDir.isFile()) {
- throw new InvalidModificationException("Can't rename a file to a directory");
- }
-
- // Check to make sure we are not copying the directory into itself
- if (isCopyOnItself(srcDir.getAbsolutePath(), destinationDir.getAbsolutePath())) {
- throw new InvalidModificationException("Can't copy itself into itself");
- }
-
- // See if the destination directory exists. If not create it.
- if (!destinationDir.exists()) {
- if (!destinationDir.mkdir()) {
- // If we can't create the directory then fail
- throw new NoModificationAllowedException("Couldn't create the destination directory");
- }
- }
-
-
- for (File file : srcDir.listFiles()) {
- File destination = new File(destinationDir.getAbsoluteFile() + File.separator + file.getName());
- if (file.isDirectory()) {
- copyDirectory(file, destination);
- } else {
- copyFile(file, destination);
- }
- }
-
- return getEntry(destinationDir);
- }
-
- /**
- * Check to see if the user attempted to copy an entry into its parent without changing its name,
- * or attempted to copy a directory into a directory that it contains directly or indirectly.
- *
- * @param srcDir
- * @param destinationDir
- * @return
- */
- private boolean isCopyOnItself(String src, String dest) {
-
- // This weird test is to determine if we are copying or moving a directory into itself.
- // Copy /sdcard/myDir to /sdcard/myDir-backup is okay but
- // Copy /sdcard/myDir to /sdcard/myDir/backup should throw an INVALID_MODIFICATION_ERR
- if (dest.startsWith(src) && dest.indexOf(File.separator, src.length() - 1) != -1) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Move a file
- *
- * @param srcFile file to be copied
- * @param destFile destination to be copied to
- * @return a FileEntry object
- * @throws IOException
- * @throws InvalidModificationException
- * @throws JSONException
- */
- private JSONObject moveFile(File srcFile, File destFile) throws IOException, JSONException, InvalidModificationException {
- // Renaming a file to an existing directory should fail
- if (destFile.exists() && destFile.isDirectory()) {
- throw new InvalidModificationException("Can't rename a file to a directory");
- }
-
- // Try to rename the file
- if (!srcFile.renameTo(destFile)) {
- // Trying to rename the file failed. Possibly because we moved across file system on the device.
- // Now we have to do things the hard way
- // 1) Copy all the old file
- // 2) delete the src file
- copyAction(srcFile, destFile);
- if (destFile.exists()) {
- srcFile.delete();
- } else {
- throw new IOException("moved failed");
- }
+ private JSONObject transferTo(String srcURLstr, String destURLstr, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
+ if (srcURLstr == null || destURLstr == null) {
+ // either no source or no destination provided
+ throw new FileNotFoundException();
}
- return getEntry(destFile);
- }
-
- /**
- * Move a directory
- *
- * @param srcDir directory to be copied
- * @param destinationDir destination to be copied to
- * @return a DirectoryEntry object
- * @throws JSONException
- * @throws IOException
- * @throws InvalidModificationException
- * @throws NoModificationAllowedException
- * @throws FileExistsException
- */
- private JSONObject moveDirectory(File srcDir, File destinationDir) throws IOException, JSONException, InvalidModificationException, NoModificationAllowedException, FileExistsException {
- // Renaming a file to an existing directory should fail
- if (destinationDir.exists() && destinationDir.isFile()) {
- throw new InvalidModificationException("Can't rename a file to a directory");
- }
-
- // Check to make sure we are not copying the directory into itself
- if (isCopyOnItself(srcDir.getAbsolutePath(), destinationDir.getAbsolutePath())) {
- throw new InvalidModificationException("Can't move itself into itself");
- }
+ LocalFilesystemURL srcURL = new LocalFilesystemURL(srcURLstr);
+ LocalFilesystemURL destURL = new LocalFilesystemURL(destURLstr);
- // If the destination directory already exists and is empty then delete it. This is according to spec.
- if (destinationDir.exists()) {
- if (destinationDir.list().length > 0) {
- throw new InvalidModificationException("directory is not empty");
- }
- }
+ Filesystem srcFs = this.filesystemForURL(srcURL);
+ Filesystem destFs = this.filesystemForURL(destURL);
- // Try to rename the directory
- if (!srcDir.renameTo(destinationDir)) {
- // Trying to rename the directory failed. Possibly because we moved across file system on the device.
- // Now we have to do things the hard way
- // 1) Copy all the old files
- // 2) delete the src directory
- copyDirectory(srcDir, destinationDir);
- if (destinationDir.exists()) {
- removeDirRecursively(srcDir);
- } else {
- throw new IOException("moved failed");
- }
+ // Check for invalid file name
+ if (newName != null && newName.contains(":")) {
+ throw new EncodingException("Bad file name");
}
- return getEntry(destinationDir);
+ return destFs.copyFileToURL(destURL, newName, srcFs, srcURL, move);
}
/**
@@ -759,28 +516,6 @@ public class FileUtils extends CordovaPlugin {
}
}
- /**
- * Loops through a directory deleting all the files.
- *
- * @param directory to be removed
- * @return a boolean representing success of failure
- * @throws FileExistsException
- */
- /* TODO: Remove when no longer needed */
- private boolean removeDirRecursively(File directory) throws FileExistsException {
-
- if (directory.isDirectory()) {
- for (File file : directory.listFiles()) {
- removeDirRecursively(file);
- }
- }
-
- if (!directory.delete()) {
- throw new FileExistsException("could not delete: " + directory.getName());
- } else {
- return true;
- }
- }
/**
* Deletes a file or directory. It is an error to attempt to delete a directory that is not empty.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/1a6c80b0/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 625cf5f..cbec37a 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -25,4 +25,7 @@ public interface Filesystem {
JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+ JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
+ Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/1a6c80b0/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index f2137b3..e2f5de1 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -1,8 +1,11 @@
package org.apache.cordova.file;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.channels.FileChannel;
import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
@@ -49,6 +52,10 @@ public class LocalFilesystem implements Filesystem {
return entry;
}
+
+ public JSONObject makeEntryForFile(File file, int fsType) throws JSONException {
+ return makeEntryForPath(this.fullPathForFilesystemPath(file.getAbsolutePath()), fsType, file.isDirectory());
+ }
@Override
public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
@@ -248,4 +255,294 @@ public class LocalFilesystem implements Filesystem {
return getEntryForLocalURL(newURL);
}
+ /**
+ * Check to see if the user attempted to copy an entry into its parent without changing its name,
+ * or attempted to copy a directory into a directory that it contains directly or indirectly.
+ *
+ * @param srcDir
+ * @param destinationDir
+ * @return
+ */
+ private boolean isCopyOnItself(String src, String dest) {
+
+ // This weird test is to determine if we are copying or moving a directory into itself.
+ // Copy /sdcard/myDir to /sdcard/myDir-backup is okay but
+ // Copy /sdcard/myDir to /sdcard/myDir/backup should throw an INVALID_MODIFICATION_ERR
+ if (dest.startsWith(src) && dest.indexOf(File.separator, src.length() - 1) != -1) {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Creates the destination File object based on name passed in
+ *
+ * @param newName for the file directory to be called, if null use existing file name
+ * @param fp represents the source file
+ * @param destination represents the destination file
+ * @return a File object that represents the destination
+ */
+ private File createDestination(String newName, File fp, File destination) {
+ File destFile = null;
+
+ // I know this looks weird but it is to work around a JSON bug.
+ if ("null".equals(newName) || "".equals(newName)) {
+ newName = null;
+ }
+
+ if (newName != null) {
+ destFile = new File(destination.getAbsolutePath() + File.separator + newName);
+ } else {
+ destFile = new File(destination.getAbsolutePath() + File.separator + fp.getName());
+ }
+ return destFile;
+ }
+
+ /**
+ * Copy a file
+ *
+ * @param srcFile file to be copied
+ * @param destFile destination to be copied to
+ * @return a FileEntry object
+ * @throws IOException
+ * @throws InvalidModificationException
+ * @throws JSONException
+ */
+ private JSONObject copyFile(File srcFile, File destFile, int fsType) throws IOException, InvalidModificationException, JSONException {
+ // Renaming a file to an existing directory should fail
+ if (destFile.exists() && destFile.isDirectory()) {
+ throw new InvalidModificationException("Can't rename a file to a directory");
+ }
+
+ copyAction(srcFile, destFile);
+
+ return makeEntryForFile(destFile, fsType);
+ }
+
+ /**
+ * Moved this code into it's own method so moveTo could use it when the move is across file systems
+ */
+ private void copyAction(File srcFile, File destFile)
+ throws FileNotFoundException, IOException {
+ FileInputStream istream = new FileInputStream(srcFile);
+ FileOutputStream ostream = new FileOutputStream(destFile);
+ FileChannel input = istream.getChannel();
+ FileChannel output = ostream.getChannel();
+
+ try {
+ input.transferTo(0, input.size(), output);
+ } finally {
+ istream.close();
+ ostream.close();
+ input.close();
+ output.close();
+ }
+ }
+
+ /**
+ * Copy a directory
+ *
+ * @param srcDir directory to be copied
+ * @param destinationDir destination to be copied to
+ * @return a DirectoryEntry object
+ * @throws JSONException
+ * @throws IOException
+ * @throws NoModificationAllowedException
+ * @throws InvalidModificationException
+ */
+ private JSONObject copyDirectory(File srcDir, File destinationDir, int fsType) throws JSONException, IOException, NoModificationAllowedException, InvalidModificationException {
+ // Renaming a file to an existing directory should fail
+ if (destinationDir.exists() && destinationDir.isFile()) {
+ throw new InvalidModificationException("Can't rename a file to a directory");
+ }
+
+ // Check to make sure we are not copying the directory into itself
+ if (isCopyOnItself(srcDir.getAbsolutePath(), destinationDir.getAbsolutePath())) {
+ throw new InvalidModificationException("Can't copy itself into itself");
+ }
+
+ // See if the destination directory exists. If not create it.
+ if (!destinationDir.exists()) {
+ if (!destinationDir.mkdir()) {
+ // If we can't create the directory then fail
+ throw new NoModificationAllowedException("Couldn't create the destination directory");
+ }
+ }
+
+
+ for (File file : srcDir.listFiles()) {
+ File destination = new File(destinationDir.getAbsoluteFile() + File.separator + file.getName());
+ if (file.isDirectory()) {
+ copyDirectory(file, destination, fsType);
+ } else {
+ copyFile(file, destination, fsType);
+ }
+ }
+
+ return makeEntryForFile(destinationDir, fsType);
+ }
+
+ /**
+ * Move a file
+ *
+ * @param srcFile file to be copied
+ * @param destFile destination to be copied to
+ * @return a FileEntry object
+ * @throws IOException
+ * @throws InvalidModificationException
+ * @throws JSONException
+ */
+ private JSONObject moveFile(File srcFile, File destFile, int fsType) throws IOException, JSONException, InvalidModificationException {
+ // Renaming a file to an existing directory should fail
+ if (destFile.exists() && destFile.isDirectory()) {
+ throw new InvalidModificationException("Can't rename a file to a directory");
+ }
+
+ // Try to rename the file
+ if (!srcFile.renameTo(destFile)) {
+ // Trying to rename the file failed. Possibly because we moved across file system on the device.
+ // Now we have to do things the hard way
+ // 1) Copy all the old file
+ // 2) delete the src file
+ copyAction(srcFile, destFile);
+ if (destFile.exists()) {
+ srcFile.delete();
+ } else {
+ throw new IOException("moved failed");
+ }
+ }
+
+ return makeEntryForFile(destFile, fsType);
+ }
+
+ /**
+ * Move a directory
+ *
+ * @param srcDir directory to be copied
+ * @param destinationDir destination to be copied to
+ * @return a DirectoryEntry object
+ * @throws JSONException
+ * @throws IOException
+ * @throws InvalidModificationException
+ * @throws NoModificationAllowedException
+ * @throws FileExistsException
+ */
+ private JSONObject moveDirectory(File srcDir, File destinationDir, int fsType) throws IOException, JSONException, InvalidModificationException, NoModificationAllowedException, FileExistsException {
+ // Renaming a file to an existing directory should fail
+ if (destinationDir.exists() && destinationDir.isFile()) {
+ throw new InvalidModificationException("Can't rename a file to a directory");
+ }
+
+ // Check to make sure we are not copying the directory into itself
+ if (isCopyOnItself(srcDir.getAbsolutePath(), destinationDir.getAbsolutePath())) {
+ throw new InvalidModificationException("Can't move itself into itself");
+ }
+
+ // If the destination directory already exists and is empty then delete it. This is according to spec.
+ if (destinationDir.exists()) {
+ if (destinationDir.list().length > 0) {
+ throw new InvalidModificationException("directory is not empty");
+ }
+ }
+
+ // Try to rename the directory
+ if (!srcDir.renameTo(destinationDir)) {
+ // Trying to rename the directory failed. Possibly because we moved across file system on the device.
+ // Now we have to do things the hard way
+ // 1) Copy all the old files
+ // 2) delete the src directory
+ copyDirectory(srcDir, destinationDir, fsType);
+ if (destinationDir.exists()) {
+ removeDirRecursively(srcDir);
+ } else {
+ throw new IOException("moved failed");
+ }
+ }
+
+ return makeEntryForFile(destinationDir, fsType);
+ }
+
+
+ @Override
+ public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
+ Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
+
+
+ String newFileName = this.filesystemPathForURL(srcURL);
+ String newParent = this.filesystemPathForURL(destURL);
+
+
+ File destinationDir = new File(newParent);
+ if (!destinationDir.exists()) {
+ // The destination does not exist so we should fail.
+ throw new FileNotFoundException("The source does not exist");
+ }
+
+
+ if (LocalFilesystem.class.isInstance(srcFs)) {
+
+ /* Same FS, we can shortcut with NSFileManager operations */
+
+
+ File source = new File(newFileName);
+
+ if (!source.exists()) {
+ // The file/directory we are copying doesn't exist so we should fail.
+ throw new FileNotFoundException("The source does not exist");
+ }
+
+ // Figure out where we should be copying to
+ File destination = createDestination(newName, source, destinationDir);
+
+ //Log.d(LOG_TAG, "Source: " + source.getAbsolutePath());
+ //Log.d(LOG_TAG, "Destin: " + destination.getAbsolutePath());
+
+ // Check to see if source and destination are the same file
+ if (source.getAbsolutePath().equals(destination.getAbsolutePath())) {
+ throw new InvalidModificationException("Can't copy a file onto itself");
+ }
+
+ if (source.isDirectory()) {
+ if (move) {
+ return moveDirectory(source, destination, destURL.filesystemType);
+ } else {
+ return copyDirectory(source, destination, destURL.filesystemType);
+ }
+ } else {
+ if (move) {
+ JSONObject newFileEntry = moveFile(source, destination, destURL.filesystemType);
+
+/* // If we've moved a file given its content URI, we need to clean up.
+ // TODO: Move this to where it belongs, in cross-fs mv code below.
+ if (srcURL.URL.getScheme().equals("content")) {
+ notifyDelete(fileName);
+ }
+*/
+ return newFileEntry;
+ } else {
+ return copyFile(source, destination, destURL.filesystemType);
+ }
+ }
+
+
+ } else {
+/* // Need to copy the hard way
+ srcFs.readFileAtURL(srcURL, 0, -1, new ReadFileCallback() {
+ void run(data, mimetype, errorcode) {
+ if (data != null) {
+ //write data to file
+ // send success message -- call original callback?
+ }
+ // error
+ }
+ });
+ return null; // Async, will return later
+*/
+ }
+ return null;
+ }
+
+
}
[03/15] git commit: CB-5407: Move read,
write and truncate methods into modules
Posted by ia...@apache.org.
CB-5407: Move read, write and truncate methods into modules
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/71452d0a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/71452d0a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/71452d0a
Branch: refs/heads/android-file
Commit: 71452d0aff093729eb754ab70c5335dbfac6e441
Parents: 1a6c80b
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Nov 28 21:37:00 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 16 +++
src/android/FileUtils.java | 182 ++++++++++++--------------------
src/android/Filesystem.java | 9 ++
src/android/LocalFilesystem.java | 89 ++++++++++++++++
4 files changed, 183 insertions(+), 113 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/71452d0a/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 6071870..17bead8 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -91,5 +91,21 @@ public class ContentFilesystem implements Filesystem {
// TODO Auto-generated method stub
return null;
}
+ @Override
+ public void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
+ ReadFileCallback readFileCallback) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
+ int offset, boolean isBinary) throws NoModificationAllowedException {
+ throw new NoModificationAllowedException("Couldn't write to file given its content URI");
+ }
+ @Override
+ public long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
+ throws NoModificationAllowedException {
+ throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/71452d0a/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 364e3d4..868e34e 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -159,7 +159,7 @@ public class FileUtils extends CordovaPlugin {
final int end = args.getInt(3);
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() {
+ public void run() throws MalformedURLException {
readFileAs(fname, start, end, callbackContext, encoding, PluginResult.MESSAGE_TYPE_STRING);
}
}, callbackContext);
@@ -169,7 +169,7 @@ public class FileUtils extends CordovaPlugin {
final int end = args.getInt(2);
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() {
+ public void run() throws MalformedURLException {
readFileAs(fname, start, end, callbackContext, null, -1);
}
}, callbackContext);
@@ -179,7 +179,7 @@ public class FileUtils extends CordovaPlugin {
final int end = args.getInt(2);
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() {
+ public void run() throws MalformedURLException {
readFileAs(fname, start, end, callbackContext, null, PluginResult.MESSAGE_TYPE_ARRAYBUFFER);
}
},callbackContext);
@@ -189,7 +189,7 @@ public class FileUtils extends CordovaPlugin {
final int end = args.getInt(2);
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() {
+ public void run() throws MalformedURLException {
readFileAs(fname, start, end, callbackContext, null, PluginResult.MESSAGE_TYPE_BINARYSTRING);
}
}, callbackContext);
@@ -715,69 +715,56 @@ public class FileUtils extends CordovaPlugin {
* @param encoding The encoding to return contents as. Typical value is UTF-8. (see http://www.iana.org/assignments/character-sets)
* @param resultType The desired type of data to send to the callback.
* @return Contents of file.
+ * @throws MalformedURLException
*/
- public void readFileAs(final String filename, final int start, final int end, final CallbackContext callbackContext, final String encoding, final int resultType) {
- this.cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- try {
- byte[] bytes = readAsBinaryHelper(filename, start, end);
-
- PluginResult result;
- switch (resultType) {
- case PluginResult.MESSAGE_TYPE_STRING:
- result = new PluginResult(PluginResult.Status.OK, new String(bytes, encoding));
- break;
- case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
- result = new PluginResult(PluginResult.Status.OK, bytes);
- break;
- case PluginResult.MESSAGE_TYPE_BINARYSTRING:
- result = new PluginResult(PluginResult.Status.OK, bytes, true);
- break;
- default: // Base64.
- String contentType = FileHelper.getMimeType(filename, cordova);
- byte[] base64 = Base64.encode(bytes, Base64.NO_WRAP);
- String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
- result = new PluginResult(PluginResult.Status.OK, s);
+ public void readFileAs(final String srcURLstr, final int start, final int end, final CallbackContext callbackContext, final String encoding, final int resultType) throws MalformedURLException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(srcURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+
+ fs.readFileAtURL(inputURL, start, end, new ReadFileCallback() {
+ public void handleData(byte[] bytes, String contentType) {
+ try {
+ PluginResult result;
+ switch (resultType) {
+ case PluginResult.MESSAGE_TYPE_STRING:
+ result = new PluginResult(PluginResult.Status.OK, new String(bytes, encoding));
+ break;
+ case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
+ result = new PluginResult(PluginResult.Status.OK, bytes);
+ break;
+ case PluginResult.MESSAGE_TYPE_BINARYSTRING:
+ result = new PluginResult(PluginResult.Status.OK, bytes, true);
+ break;
+ default: // Base64.
+ byte[] base64 = Base64.encode(bytes, Base64.NO_WRAP);
+ String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
+ result = new PluginResult(PluginResult.Status.OK, s);
+ }
+
+ callbackContext.sendPluginResult(result);
+ } catch (IOException e) {
+ Log.d(LOG_TAG, e.getLocalizedMessage());
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR));
}
+ }
+ });
- callbackContext.sendPluginResult(result);
- } catch (FileNotFoundException e) {
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_FOUND_ERR));
- } catch (IOException e) {
- Log.d(LOG_TAG, e.getLocalizedMessage());
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR));
- }
- }
- });
- }
- /**
- * Read the contents of a file as binary.
- * This is done synchronously; the result is returned.
- *
- * @param filename The name of the file.
- * @param start Start position in the file.
- * @param end End position to stop at (exclusive).
- * @return Contents of the file as a byte[].
- * @throws IOException
- */
- private byte[] readAsBinaryHelper(String filename, int start, int end) throws IOException {
- int numBytesToRead = end - start;
- byte[] bytes = new byte[numBytesToRead];
- InputStream inputStream = FileHelper.getInputStreamFromUriString(filename, cordova);
- int numBytesRead = 0;
-
- if (start > 0) {
- inputStream.skip(start);
- }
-
- while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
- numBytesToRead -= numBytesRead;
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
+ } catch (FileNotFoundException e) {
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_FOUND_ERR));
+ } catch (IOException e) {
+ Log.d(LOG_TAG, e.getLocalizedMessage());
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR));
}
-
- return bytes;
}
+
/**
* Write contents of file.
*
@@ -789,43 +776,19 @@ public class FileUtils extends CordovaPlugin {
* @throws NoModificationAllowedException
*/
/**/
- public long write(String filename, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException {
- if (filename.startsWith("content://")) {
- throw new NoModificationAllowedException("Couldn't write to file given its content URI");
- }
-
- filename = FileHelper.getRealPath(filename, cordova);
-
- boolean append = false;
- if (offset > 0) {
- this.truncateFile(filename, offset);
- append = true;
- }
-
- byte[] rawData;
- if (isBinary) {
- rawData = Base64.decode(data, Base64.DEFAULT);
- } else {
- rawData = data.getBytes();
- }
- ByteArrayInputStream in = new ByteArrayInputStream(rawData);
- try
- {
- FileOutputStream out = new FileOutputStream(filename, append);
- byte buff[] = new byte[rawData.length];
- in.read(buff, 0, buff.length);
- out.write(buff, 0, rawData.length);
- out.flush();
- out.close();
- }
- catch (NullPointerException e)
- {
- // This is a bug in the Android implementation of the Java Stack
- NoModificationAllowedException realException = new NoModificationAllowedException(filename);
- throw realException;
+ public long write(String srcURLstr, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(srcURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+
+ long x = fs.writeToFileAtURL(inputURL, data, offset, isBinary); Log.d("TEST",srcURLstr + ": "+x); return x;
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
-
- return rawData.length;
+
}
/**
@@ -836,24 +799,17 @@ public class FileUtils extends CordovaPlugin {
* @throws FileNotFoundException, IOException
* @throws NoModificationAllowedException
*/
- private long truncateFile(String filename, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
- if (filename.startsWith("content://")) {
- throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
- }
-
- filename = FileHelper.getRealPath(filename, cordova);
-
- RandomAccessFile raf = new RandomAccessFile(filename, "rw");
+ private long truncateFile(String srcURLstr, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
try {
- if (raf.length() >= size) {
- FileChannel channel = raf.getChannel();
- channel.truncate(size);
- return size;
- }
-
- return raf.length();
- } finally {
- raf.close();
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(srcURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+
+ return fs.truncateFileAtURL(inputURL, size);
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
}
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/71452d0a/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index cbec37a..6955520 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -28,4 +28,13 @@ public interface Filesystem {
JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException;
+ void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
+ ReadFileCallback readFileCallback) throws IOException;
+
+ long writeToFileAtURL(LocalFilesystemURL inputURL, String data, int offset,
+ boolean isBinary) throws NoModificationAllowedException, IOException;
+
+ long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
+ throws IOException, NoModificationAllowedException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/71452d0a/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index e2f5de1..2613329 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -1,10 +1,13 @@
package org.apache.cordova.file;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import org.apache.cordova.CordovaInterface;
@@ -544,5 +547,91 @@ public class LocalFilesystem implements Filesystem {
return null;
}
+ @Override
+ public void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
+ ReadFileCallback readFileCallback) throws IOException {
+
+ int numBytesToRead = end - start;
+ byte[] bytes = new byte[numBytesToRead];
+ String contentType;
+
+ File file = new File(this.filesystemPathForURL(inputURL));
+ InputStream inputStream = new FileInputStream(file);
+
+ contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
+ int numBytesRead = 0;
+
+ if (start > 0) {
+ inputStream.skip(start);
+ }
+
+ while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
+ numBytesToRead -= numBytesRead;
+ }
+ inputStream.close();
+ readFileCallback.handleData(bytes, contentType);
+ }
+
+ @Override
+ public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
+ int offset, boolean isBinary) throws IOException, NoModificationAllowedException {
+ File file = new File(filesystemPathForURL(inputURL));
+
+ boolean append = false;
+ if (offset > 0) {
+ this.truncateFileAtURL(inputURL, offset);
+ append = true;
+ }
+
+ byte[] rawData;
+ if (isBinary) {
+ rawData = Base64.decode(data, Base64.DEFAULT);
+ } else {
+ rawData = data.getBytes();
+ }
+ ByteArrayInputStream in = new ByteArrayInputStream(rawData);
+ try
+ {
+ FileOutputStream out = new FileOutputStream(this.filesystemPathForURL(inputURL), append);
+ byte buff[] = new byte[rawData.length];
+ in.read(buff, 0, buff.length);
+ out.write(buff, 0, rawData.length);
+ out.flush();
+ out.close();
+ }
+ catch (NullPointerException e)
+ {
+ // This is a bug in the Android implementation of the Java Stack
+ NoModificationAllowedException realException = new NoModificationAllowedException(inputURL.toString());
+ throw realException;
+ }
+
+ return rawData.length;
+ }
+
+ @Override
+ public long truncateFileAtURL(LocalFilesystemURL inputURL, long size) throws IOException {
+ File file = new File(filesystemPathForURL(inputURL));
+
+ if (!file.exists()) {
+ throw new FileNotFoundException("File at " + inputURL.URL + " does not exist.");
+ }
+
+ RandomAccessFile raf = new RandomAccessFile(filesystemPathForURL(inputURL), "rw");
+ try {
+ if (raf.length() >= size) {
+ FileChannel channel = raf.getChannel();
+ channel.truncate(size);
+ return size;
+ }
+
+ return raf.length();
+ } finally {
+ raf.close();
+ }
+
+
+ }
+
}
[11/15] git commit: CB-5407: Move getmetadata methods into FS modules
Posted by ia...@apache.org.
CB-5407: Move getmetadata methods into FS modules
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/836c6733
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/836c6733
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/836c6733
Branch: refs/heads/android-file
Commit: 836c67338c4be8e66d340f1e5c9f119285ee5d35
Parents: 03fcd12
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Nov 27 14:36:19 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 5 ++++
src/android/FileUtils.java | 50 +++++++++++----------------------
src/android/Filesystem.java | 3 ++
src/android/LocalFilesystem.java | 22 +++++++++++++++
4 files changed, 46 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 8fef685..17fddcb 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -71,5 +71,10 @@ public class ContentFilesystem implements Filesystem {
// TODO Auto-generated method stub
return null;
}
+ @Override
+ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 01ce90b..8e050c5 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -242,15 +242,16 @@ public class FileUtils extends CordovaPlugin {
else if (action.equals("getMetadata")) {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() throws FileNotFoundException, JSONException {
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getMetadata(fname)));
+ public void run() throws FileNotFoundException, JSONException, MalformedURLException {
+ JSONObject obj = getFileMetadata(fname);
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, obj.getLong("lastModifiedDate")));
}
}, callbackContext);
}
else if (action.equals("getFileMetadata")) {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() throws FileNotFoundException, JSONException {
+ public void run() throws FileNotFoundException, JSONException, MalformedURLException {
JSONObject obj = getFileMetadata(fname);
callbackContext.success(obj);
}
@@ -891,45 +892,26 @@ public class FileUtils extends CordovaPlugin {
}
/**
- * Look up metadata about this entry.
- *
- * @param filePath to entry
- * @return a long
- * @throws FileNotFoundException
- */
- private long getMetadata(String filePath) throws FileNotFoundException {
- File file = createFileObject(filePath);
-
- if (!file.exists()) {
- throw new FileNotFoundException("Failed to find file in getMetadata");
- }
-
- return file.lastModified();
- }
-
- /**
* Returns a File that represents the current state of the file that this FileEntry represents.
*
* @param filePath to entry
* @return returns a JSONObject represent a W3C File object
* @throws FileNotFoundException
* @throws JSONException
+ * @throws MalformedURLException
*/
- private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException {
- File file = createFileObject(filePath);
-
- if (!file.exists()) {
- throw new FileNotFoundException("File: " + filePath + " does not exist.");
+ private JSONObject getFileMetadata(String baseURLstr) throws FileNotFoundException, JSONException, MalformedURLException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.getFileMetadataForLocalURL(inputURL);
+
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
-
- JSONObject metadata = new JSONObject();
- metadata.put("size", file.length());
- metadata.put("type", FileHelper.getMimeType(filePath, cordova));
- metadata.put("name", file.getName());
- metadata.put("fullPath", filePath);
- metadata.put("lastModifiedDate", file.lastModified());
-
- return metadata;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 4abd403..d627d10 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -3,6 +3,7 @@ package org.apache.cordova.file;
import java.io.FileNotFoundException;
import java.io.IOException;
+import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -20,4 +21,6 @@ public interface Filesystem {
JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+ JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 7d3aacb..3d11cf2 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -214,4 +215,25 @@ public class LocalFilesystem implements Filesystem {
return null;
}
+ @Override
+ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
+ File file = new File(filesystemPathForURL(inputURL));
+
+ if (!file.exists()) {
+ throw new FileNotFoundException("File at " + inputURL.URL + " does not exist.");
+ }
+
+ JSONObject metadata = new JSONObject();
+ try {
+ metadata.put("size", file.length());
+ metadata.put("type", FileHelper.getMimeType(file.getAbsolutePath(), cordova));
+ metadata.put("name", file.getName());
+ metadata.put("fullPath", inputURL.fullPath);
+ metadata.put("lastModifiedDate", file.lastModified());
+ } catch (JSONException e) {
+ return null;
+ }
+ return metadata;
+ }
+
}
[07/15] git commit: CB-5407: Move getFile into FS modules
Posted by ia...@apache.org.
CB-5407: Move getFile into FS modules
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/3fd4e1b3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3fd4e1b3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3fd4e1b3
Branch: refs/heads/android-file
Commit: 3fd4e1b367d8d59edb5ead55c5544528230919b1
Parents: 96d632f
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Nov 25 11:05:28 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 5 ++
src/android/FileUtils.java | 81 +++++--------------------
src/android/Filesystem.java | 4 ++
src/android/LocalFilesystem.java | 101 ++++++++++++++++++++++++++++++++
4 files changed, 124 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fd4e1b3/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index bef40a3..6b34641 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -49,5 +49,10 @@ public class ContentFilesystem implements Filesystem {
throw new IOException();
}
}
+ @Override
+ public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
+ String fileName, JSONObject options, boolean directory) throws IOException {
+ throw new IOException("Cannot create content url");
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fd4e1b3/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
old mode 100755
new mode 100644
index 473af3e..32e2a4a
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -418,11 +418,11 @@ public class FileUtils extends CordovaPlugin {
LocalFilesystemURL inputURL = new LocalFilesystemURL(decoded);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
- throw new MalformedURLException("Unrecognized filesystem URL");
+ throw new MalformedURLException("No installed handlers for this URL");
}
return fs.getEntryForLocalURL(inputURL);
} catch (IllegalArgumentException e) {
- throw new IOException();
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
}
@@ -804,7 +804,7 @@ public class FileUtils extends CordovaPlugin {
/**
* Creates or looks up a file.
*
- * @param dirPath base directory
+ * @param baseURLstr base directory
* @param fileName file/directory to lookup or create
* @param options specify whether to create or not
* @param directory if true look up directory, if false look up file
@@ -815,72 +815,19 @@ public class FileUtils extends CordovaPlugin {
* @throws EncodingException
* @throws JSONException
*/
- private JSONObject getFile(String dirPath, String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
- boolean create = false;
- boolean exclusive = false;
- if (options != null) {
- create = options.optBoolean("create");
- if (create) {
- exclusive = options.optBoolean("exclusive");
- }
- }
-
- // Check for a ":" character in the file to line up with BB and iOS
- if (fileName.contains(":")) {
- throw new EncodingException("This file has a : in it's name");
- }
-
- File fp = createFileObject(dirPath, fileName);
-
- if (create) {
- if (exclusive && fp.exists()) {
- throw new FileExistsException("create/exclusive fails");
- }
- if (directory) {
- fp.mkdir();
- } else {
- fp.createNewFile();
- }
- if (!fp.exists()) {
- throw new FileExistsException("create fails");
- }
- }
- else {
- if (!fp.exists()) {
- throw new FileNotFoundException("path does not exist");
- }
- if (directory) {
- if (fp.isFile()) {
- throw new TypeMismatchException("path doesn't exist or is file");
- }
- } else {
- if (fp.isDirectory()) {
- throw new TypeMismatchException("path doesn't exist or is directory");
- }
- }
+ private JSONObject getFile(String baseURLstr, String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.getFileForLocalURL(inputURL, fileName, options, directory);
+
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
- // Return the directory
- return getEntry(fp);
- }
-
- /**
- * If the path starts with a '/' just return that file object. If not construct the file
- * object from the path passed in and the file name.
- *
- * @param dirPath root directory
- * @param fileName new file name
- * @return
- */
- private File createFileObject(String dirPath, String fileName) {
- File fp = null;
- if (fileName.startsWith("/")) {
- fp = new File(fileName);
- } else {
- dirPath = FileHelper.getRealPath(dirPath, cordova);
- fp = new File(dirPath + File.separator + fileName);
- }
- return fp;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fd4e1b3/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 1879ad0..19692ad 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -2,10 +2,14 @@ package org.apache.cordova.file;
import java.io.IOException;
+import org.json.JSONException;
import org.json.JSONObject;
public interface Filesystem {
JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+ JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String fileName,
+ JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fd4e1b3/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index c005867..563f8ed 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -8,6 +8,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import android.util.Base64;
+import android.net.Uri;
public class LocalFilesystem implements Filesystem {
@@ -21,6 +22,33 @@ public class LocalFilesystem implements Filesystem {
this.cordova = cordova;
}
+ public String filesystemPathForURL(LocalFilesystemURL url) {
+ String path = this.fsRoot + url.fullPath;
+ if (path.endsWith("/")) {
+ path = path.substring(0, path.length()-1);
+ }
+ return path;
+ }
+
+ public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
+ JSONObject entry = new JSONObject();
+
+ int end = path.endsWith("/") ? 1 : 0;
+ String[] parts = path.substring(0,path.length()-end).split("/");
+ String name = parts[parts.length-1];
+ Log.d("FILEDEBUG", name);
+ entry.put("isFile", !isDir);
+ entry.put("isDirectory", isDir);
+ entry.put("name", name);
+ entry.put("fullPath", path);
+ // The file system can't be specified, as it would lead to an infinite loop,
+ // but the filesystem type can
+ entry.put("filesystem", fsType);
+
+ return entry;
+
+ }
+
@Override
public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
File fp = null;
@@ -47,4 +75,77 @@ public class LocalFilesystem implements Filesystem {
}
}
+ /**
+ * If the path starts with a '/' just return that file object. If not construct the file
+ * object from the path passed in and the file name.
+ *
+ * @param dirPath root directory
+ * @param fileName new file name
+ * @return
+ */
+ private File createFileObject(String dirPath, String fileName) {
+ File fp = null;
+ if (fileName.startsWith("/")) {
+ fp = new File(this.fsRoot + fileName);
+ } else {
+ fp = new File(this.fsRoot + File.separator + dirPath + File.separator + fileName);
+ }
+ return fp;
+ }
+
+
+ @Override
+ public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
+ String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
+ boolean create = false;
+ boolean exclusive = false;
+
+ if (options != null) {
+ create = options.optBoolean("create");
+ if (create) {
+ exclusive = options.optBoolean("exclusive");
+ }
+ }
+
+ // Check for a ":" character in the file to line up with BB and iOS
+ if (fileName.contains(":")) {
+ throw new EncodingException("This file has a : in it's name");
+ }
+
+ LocalFilesystemURL requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, fileName));
+
+ File fp = new File(this.filesystemPathForURL(requestedURL));
+
+ if (create) {
+ if (exclusive && fp.exists()) {
+ throw new FileExistsException("create/exclusive fails");
+ }
+ if (directory) {
+ fp.mkdir();
+ } else {
+ fp.createNewFile();
+ }
+ if (!fp.exists()) {
+ throw new FileExistsException("create fails");
+ }
+ }
+ else {
+ if (!fp.exists()) {
+ throw new FileNotFoundException("path does not exist");
+ }
+ if (directory) {
+ if (fp.isFile()) {
+ throw new TypeMismatchException("path doesn't exist or is file");
+ }
+ } else {
+ if (fp.isDirectory()) {
+ throw new TypeMismatchException("path doesn't exist or is directory");
+ }
+ }
+ }
+
+ // Return the directory
+ return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemType, directory);
+ }
+
}
[09/15] git commit: CB-5407: Move getParent into FS modules
Posted by ia...@apache.org.
CB-5407: Move getParent into FS modules
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/afee8d8a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/afee8d8a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/afee8d8a
Branch: refs/heads/android-file
Commit: afee8d8a6f7c918684ad4fa80aad226531b057ba
Parents: 836c673
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Dec 2 16:04:53 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 7 +++++
src/android/FileUtils.java | 53 ++++++++-------------------------
src/android/Filesystem.java | 2 ++
src/android/LocalFilesystem.java | 12 ++++++++
4 files changed, 34 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/afee8d8a/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 17fddcb..3b4e4c3 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -76,5 +76,12 @@ public class ContentFilesystem implements Filesystem {
// TODO Auto-generated method stub
return null;
}
+ @Override
+ public JSONObject getParentForLocalURL(LocalFilesystemURL inputURL)
+ throws IOException {
+ // TODO Auto-generated method stub
+ // Can probably use same impl as LFS
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/afee8d8a/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 8e050c5..8e3bea6 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -260,7 +260,7 @@ public class FileUtils extends CordovaPlugin {
else if (action.equals("getParent")) {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() throws JSONException {
+ public void run() throws JSONException, IOException {
JSONObject obj = getParent(fname);
callbackContext.success(obj);
}
@@ -848,47 +848,20 @@ public class FileUtils extends CordovaPlugin {
* @param filePath
* @return
* @throws JSONException
+ * @throws IOException
*/
- private JSONObject getParent(String filePath) throws JSONException {
- filePath = FileHelper.getRealPath(filePath, cordova);
-
- if (atRootDirectory(filePath)) {
- return getEntry(filePath);
- }
- return getEntry(new File(filePath).getParent());
- }
-
- /**
- * Checks to see if we are at the root directory. Useful since we are
- * not allow to delete this directory.
- *
- * @param filePath to directory
- * @return true if we are at the root, false otherwise.
- */
- /* TODO: Remove when no longer needed */
- private boolean atRootDirectory(String filePath) {
- filePath = FileHelper.getRealPath(filePath, cordova);
-
- if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
- filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
- filePath.equals("/data/data/" + cordova.getActivity().getPackageName())) {
- return true;
+ private JSONObject getParent(String baseURLstr) throws JSONException, IOException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.getParentForLocalURL(inputURL);
+
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
- return false;
- }
-
- /**
- * Create a File object from the passed in path
- *
- * @param filePath
- * @return
- */
- /* TODO: Remove when no longer needed */
- private File createFileObject(String filePath) {
- filePath = FileHelper.getRealPath(filePath, cordova);
-
- File file = new File(filePath);
- return file;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/afee8d8a/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index d627d10..625cf5f 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -23,4 +23,6 @@ public interface Filesystem {
JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+ JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/afee8d8a/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 3d11cf2..f2137b3 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -236,4 +236,16 @@ public class LocalFilesystem implements Filesystem {
return metadata;
}
+ @Override
+ public JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException {
+ LocalFilesystemURL newURL = new LocalFilesystemURL(inputURL.URL);
+
+ if (!("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath))) {
+ int end = inputURL.fullPath.endsWith("/") ? 1 : 0;
+ int lastPathStartsAt = inputURL.fullPath.lastIndexOf('/', inputURL.fullPath.length()-end)+1;
+ newURL.fullPath = newURL.fullPath.substring(0,lastPathStartsAt);
+ }
+ return getEntryForLocalURL(newURL);
+ }
+
}
[08/15] git commit: CB-5407: Move remove methods into FS modules
Posted by ia...@apache.org.
CB-5407: Move remove methods into FS modules
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/21b73d6f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/21b73d6f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/21b73d6f
Branch: refs/heads/android-file
Commit: 21b73d6f1521e412cd4ac3a2817439262109851e
Parents: 3fd4e1b
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Nov 27 13:35:26 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 10 ++++++
src/android/FileUtils.java | 59 ++++++++++++++++++++++-----------
src/android/Filesystem.java | 4 +++
src/android/LocalFilesystem.java | 33 ++++++++++++++++++
4 files changed, 86 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21b73d6f/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 6b34641..7325ac6 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -54,5 +54,15 @@ public class ContentFilesystem implements Filesystem {
String fileName, JSONObject options, boolean directory) throws IOException {
throw new IOException("Cannot create content url");
}
+ @Override
+ public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL)
+ throws NoModificationAllowedException {
+ throw new NoModificationAllowedException("Cannot remove content url");
+ }
+ @Override
+ public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL)
+ throws NoModificationAllowedException {
+ throw new NoModificationAllowedException("Cannot remove content url");
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21b73d6f/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 32e2a4a..a373d50 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -288,7 +288,7 @@ public class FileUtils extends CordovaPlugin {
else if (action.equals("remove")) {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() throws NoModificationAllowedException, InvalidModificationException {
+ public void run() throws NoModificationAllowedException, InvalidModificationException, MalformedURLException {
boolean success= remove(fname);
if (success) {
notifyDelete(fname);
@@ -302,7 +302,7 @@ public class FileUtils extends CordovaPlugin {
else if (action.equals("removeRecursively")) {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
- public void run() throws FileExistsException {
+ public void run() throws FileExistsException, MalformedURLException, NoModificationAllowedException {
boolean success = removeRecursively(fname);
if (success) {
callbackContext.success();
@@ -743,16 +743,26 @@ public class FileUtils extends CordovaPlugin {
* @param filePath the directory to be removed
* @return a boolean representing success of failure
* @throws FileExistsException
+ * @throws NoModificationAllowedException
+ * @throws MalformedURLException
*/
- private boolean removeRecursively(String filePath) throws FileExistsException {
- File fp = createFileObject(filePath);
+ private boolean removeRecursively(String baseURLstr) throws FileExistsException, NoModificationAllowedException, MalformedURLException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ // You can't delete the root directory.
+ if ("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath)) {
+ throw new NoModificationAllowedException("You can't delete the root directory");
+ }
- // You can't delete the root directory.
- if (atRootDirectory(filePath)) {
- return false;
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.recursiveRemoveFileAtLocalURL(inputURL);
+
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
-
- return removeDirRecursively(fp);
}
/**
@@ -762,7 +772,9 @@ public class FileUtils extends CordovaPlugin {
* @return a boolean representing success of failure
* @throws FileExistsException
*/
+ /* TODO: Remove when no longer needed */
private boolean removeDirRecursively(File directory) throws FileExistsException {
+
if (directory.isDirectory()) {
for (File file : directory.listFiles()) {
removeDirRecursively(file);
@@ -784,21 +796,26 @@ public class FileUtils extends CordovaPlugin {
* @return a boolean representing success of failure
* @throws NoModificationAllowedException
* @throws InvalidModificationException
+ * @throws MalformedURLException
*/
- private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException {
- File fp = createFileObject(filePath);
+ private boolean remove(String baseURLstr) throws NoModificationAllowedException, InvalidModificationException, MalformedURLException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ // You can't delete the root directory.
+ if ("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath)) {
- // You can't delete the root directory.
- if (atRootDirectory(filePath)) {
- throw new NoModificationAllowedException("You can't delete the root directory");
- }
+ throw new NoModificationAllowedException("You can't delete the root directory");
+ }
- // You can't delete a directory that is not empty
- if (fp.isDirectory() && fp.list().length > 0) {
- throw new InvalidModificationException("You can't delete a directory that is not empty.");
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.removeFileAtLocalURL(inputURL);
+
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
}
-
- return fp.delete();
}
/**
@@ -854,6 +871,7 @@ public class FileUtils extends CordovaPlugin {
* @param filePath to directory
* @return true if we are at the root, false otherwise.
*/
+ /* TODO: Remove when no longer needed */
private boolean atRootDirectory(String filePath) {
filePath = FileHelper.getRealPath(filePath, cordova);
@@ -871,6 +889,7 @@ public class FileUtils extends CordovaPlugin {
* @param filePath
* @return
*/
+ /* TODO: Remove when no longer needed */
private File createFileObject(String filePath) {
filePath = FileHelper.getRealPath(filePath, cordova);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21b73d6f/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 19692ad..a4730ba 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -12,4 +12,8 @@ public interface Filesystem {
JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String fileName,
JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;
+ boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) throws InvalidModificationException, NoModificationAllowedException;
+
+ boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) throws FileExistsException, NoModificationAllowedException;
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21b73d6f/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 563f8ed..aca9d15 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -148,4 +148,37 @@ public class LocalFilesystem implements Filesystem {
return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemType, directory);
}
+ @Override
+ public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) throws InvalidModificationException {
+
+ File fp = new File(filesystemPathForURL(inputURL));
+
+ // You can't delete a directory that is not empty
+ if (fp.isDirectory() && fp.list().length > 0) {
+ throw new InvalidModificationException("You can't delete a directory that is not empty.");
+ }
+
+ return fp.delete();
+ }
+
+ @Override
+ public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) throws FileExistsException {
+ File directory = new File(filesystemPathForURL(inputURL));
+ return removeDirRecursively(directory);
+ }
+
+ protected boolean removeDirRecursively(File directory) throws FileExistsException {
+ if (directory.isDirectory()) {
+ for (File file : directory.listFiles()) {
+ removeDirRecursively(file);
+ }
+ }
+
+ if (!directory.delete()) {
+ throw new FileExistsException("could not delete: " + directory.getName());
+ } else {
+ return true;
+ }
+ }
+
}
[02/15] git commit: CB-5407: Cleanup
Posted by ia...@apache.org.
CB-5407: Cleanup
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/cfc34263
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/cfc34263
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/cfc34263
Branch: refs/heads/android-file
Commit: cfc342630f929209f3131a22dd0d44d512b4fd0c
Parents: 71452d0
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Nov 28 21:42:19 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 76 ++++++++++-------------------------
src/android/LocalFilesystem.java | 20 ---------
2 files changed, 21 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/cfc34263/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 868e34e..00483bc 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -33,17 +33,11 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URLDecoder;
-import java.nio.channels.FileChannel;
import java.util.ArrayList;
/**
@@ -632,55 +626,23 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject requestFileSystem(int type) throws IOException, JSONException {
JSONObject fs = new JSONObject();
+ LocalFilesystemURL rootURL;
if (type == TEMPORARY) {
- File fp;
fs.put("name", "temporary");
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
- // Create the cache dir if it doesn't exist.
- fp.mkdirs();
- fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/"));
- } else {
- fp = new File("/data/data/" + cordova.getActivity().getPackageName() + "/cache/");
- // Create the cache dir if it doesn't exist.
- fp.mkdirs();
- fs.put("root", getEntry("/data/data/" + cordova.getActivity().getPackageName() + "/cache/"));
- }
+ rootURL = new LocalFilesystemURL("filesystem://localhost/temporary/");
}
else if (type == PERSISTENT) {
fs.put("name", "persistent");
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- fs.put("root", getEntry(Environment.getExternalStorageDirectory()));
- } else {
- fs.put("root", getEntry("/data/data/" + cordova.getActivity().getPackageName()));
- }
+ rootURL = new LocalFilesystemURL("filesystem://localhost/persistent/");
}
else {
throw new IOException("No filesystem of type requested");
}
- fs.put("root", makeEntryForPath("/", type, true));
+ Filesystem rootFs = this.filesystemForURL(rootURL);
+ fs.put("root", rootFs.getEntryForLocalURL(rootURL));
return fs;
}
- public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
- JSONObject entry = new JSONObject();
-
- int end = path.endsWith("/") ? 1 : 0;
- String[] parts = path.substring(0,path.length()-end).split("/",1);
- String name = parts[parts.length-1];
- entry.put("isFile", !isDir);
- entry.put("isDirectory", isDir);
- entry.put("name", name);
- entry.put("fullPath", path);
- // The file system can't be specified, as it would lead to an infinite loop,
- // but the filesystem type can
- entry.put("filesystem", fsType);
-
- return entry;
-
- }
/**
* Returns a JSON object representing the given File.
*
@@ -690,18 +652,22 @@ public class FileUtils extends CordovaPlugin {
*/
@Deprecated
public static JSONObject getEntry(File file) throws JSONException {
- return makeEntryForPath(file.getAbsolutePath(), 0, file.isDirectory());
- }
-
- /**
- * Returns a JSON Object representing a directory on the device's file system
- *
- * @param path to the directory
- * @return
- * @throws JSONException
- */
- private JSONObject getEntry(String path) throws JSONException {
- return getEntry(new File(path));
+ String path = file.getAbsolutePath();
+ Boolean isDir = file.isDirectory();
+ JSONObject entry = new JSONObject();
+
+ int end = path.endsWith("/") ? 1 : 0;
+ String[] parts = path.substring(0,path.length()-end).split("/",1);
+ String name = parts[parts.length-1];
+ entry.put("isFile", !isDir);
+ entry.put("isDirectory", isDir);
+ entry.put("name", name);
+ entry.put("fullPath", path);
+ // The file system can't be specified, as it would lead to an infinite loop,
+ // but the filesystem type can
+ entry.put("filesystem", 0);
+
+ return entry;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/cfc34263/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 2613329..adb3ef6 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -86,25 +86,6 @@ public class LocalFilesystem implements Filesystem {
}
}
- /**
- * If the path starts with a '/' just return that file object. If not construct the file
- * object from the path passed in and the file name.
- *
- * @param dirPath root directory
- * @param fileName new file name
- * @return
- */
- private File createFileObject(String dirPath, String fileName) {
- File fp = null;
- if (fileName.startsWith("/")) {
- fp = new File(this.fsRoot + fileName);
- } else {
- fp = new File(this.fsRoot + File.separator + dirPath + File.separator + fileName);
- }
- return fp;
- }
-
-
@Override
public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
@@ -575,7 +556,6 @@ public class LocalFilesystem implements Filesystem {
@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws IOException, NoModificationAllowedException {
- File file = new File(filesystemPathForURL(inputURL));
boolean append = false;
if (offset > 0) {
[04/15] git commit: CB-5405: Use URL formatting for Entry.toURL
Posted by ia...@apache.org.
CB-5405: Use URL formatting for Entry.toURL
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/abf2c05d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/abf2c05d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/abf2c05d
Branch: refs/heads/android-file
Commit: abf2c05dde49ed525ddff3165de88676d2783e73
Parents: 2685ae6
Author: Ian Clelland <ic...@chromium.org>
Authored: Sun Nov 24 22:43:59 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500
----------------------------------------------------------------------
www/Entry.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/abf2c05d/www/Entry.js
----------------------------------------------------------------------
diff --git a/www/Entry.js b/www/Entry.js
index bb4d753..223e2bc 100644
--- a/www/Entry.js
+++ b/www/Entry.js
@@ -169,8 +169,11 @@ Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallbac
* Return a URL that can be used to identify this entry.
*/
Entry.prototype.toURL = function() {
+ if (this.filesystem && this.filesystem.__format__) {
+ return this.filesystem.__format__(this.fullPath);
+ }
// fullPath attribute contains the full URL
- return this.fullPath;
+ return "file://localhost" + this.fullPath;
};
/**
[12/15] git commit: Merge branch 'android-fle' into dev
Posted by ia...@apache.org.
Merge branch 'android-fle' into dev
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/9125371b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9125371b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9125371b
Branch: refs/heads/android-file
Commit: 9125371b83df0dabe48c049ae205b8e84a86c0c6
Parents: 2685ae6 cfc3426
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Dec 11 09:59:32 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 09:59:32 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 111 ++++
src/android/FileUtils.java | 900 +++++++++----------------------
src/android/Filesystem.java | 40 ++
src/android/LocalFilesystem.java | 617 +++++++++++++++++++++
src/android/LocalFilesystemURL.java | 54 ++
www/Entry.js | 5 +-
6 files changed, 1071 insertions(+), 656 deletions(-)
----------------------------------------------------------------------