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:18:55 UTC
[13/19] git commit: CB-5407: Cleanup
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/25506177
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/25506177
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/25506177
Branch: refs/heads/dev
Commit: 2550617750d4b81c66066455417537c800411625
Parents: 9f3bb54
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Nov 28 21:42:19 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:00:35 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/25506177/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/25506177/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) {