You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2013/10/01 23:45:58 UTC
[4/4] android commit: Backporting FileUtils fixes to 2.9
Backporting FileUtils fixes to 2.9
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/0e9b446a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/0e9b446a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/0e9b446a
Branch: refs/heads/2.9.x
Commit: 0e9b446a81a7aaa1a5030f4cc3adc1cf87e43532
Parents: 2cf79a1
Author: Joe Bowser <bo...@apache.org>
Authored: Tue Oct 1 14:45:41 2013 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Tue Oct 1 14:45:41 2013 -0700
----------------------------------------------------------------------
framework/src/org/apache/cordova/FileUtils.java | 41 +++++++++++---------
1 file changed, 22 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0e9b446a/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index a2f3cdc..172fe22 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -28,11 +28,9 @@ import android.util.Log;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
-import org.apache.cordova.file.EncodingException;
-import org.apache.cordova.file.FileExistsException;
-import org.apache.cordova.file.InvalidModificationException;
-import org.apache.cordova.file.NoModificationAllowedException;
-import org.apache.cordova.file.TypeMismatchException;
+import org.apache.cordova.file.*;
+
+
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -489,12 +487,13 @@ public class FileUtils extends CordovaPlugin {
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, destinationDir);
+ copyDirectory(file, destination);
} else {
- File destination = new File(destinationDir.getAbsoluteFile() + File.separator + file.getName());
copyFile(file, destination);
}
}
@@ -914,11 +913,6 @@ public class FileUtils extends CordovaPlugin {
return getEntry(new File(path));
}
-
- //--------------------------------------------------------------------------
- // LOCAL METHODS
- //--------------------------------------------------------------------------
-
/**
* Read the contents of a file.
* This is done in a background thread; the result is sent to the callback.
@@ -950,7 +944,7 @@ public class FileUtils extends CordovaPlugin {
break;
default: // Base64.
String contentType = FileHelper.getMimeType(filename, cordova);
- byte[] base64 = Base64.encode(bytes, Base64.DEFAULT);
+ 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);
}
@@ -1024,12 +1018,21 @@ public class FileUtils extends CordovaPlugin {
rawData = data.getBytes();
}
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
- 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();
+ 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;
+ }
return rawData.length;
}