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/06/12 19:36:51 UTC
android commit: [CB-2406] Add support for binary data in
FileWriter.write()
Updated Branches:
refs/heads/master a021adb7f -> 5cff144a2
[CB-2406] Add support for binary data in FileWriter.write()
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/5cff144a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/5cff144a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/5cff144a
Branch: refs/heads/master
Commit: 5cff144a22cbd840691301d5b78ba75bc365d764
Parents: a021adb
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jun 12 11:08:47 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 12 13:33:03 2013 -0400
----------------------------------------------------------------------
framework/src/org/apache/cordova/FileUtils.java | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5cff144a/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 aeca505..a2f3cdc 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -134,7 +134,7 @@ public class FileUtils extends CordovaPlugin {
this.readFileAs(args.getString(0), start, end, callbackContext, null, PluginResult.MESSAGE_TYPE_BINARYSTRING);
}
else if (action.equals("write")) {
- long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2));
+ long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2), args.getBoolean(3));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, fileSize));
}
else if (action.equals("truncate")) {
@@ -999,11 +999,12 @@ public class FileUtils extends CordovaPlugin {
* @param filename The name of the file.
* @param data The contents of the file.
* @param offset The position to begin writing the file.
+ * @param isBinary True if the file contents are base64-encoded binary data
* @throws FileNotFoundException, IOException
* @throws NoModificationAllowedException
*/
/**/
- public long write(String filename, String data, int offset) throws FileNotFoundException, IOException, 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");
}
@@ -1016,7 +1017,12 @@ public class FileUtils extends CordovaPlugin {
append = true;
}
- byte[] rawData = data.getBytes();
+ byte[] rawData;
+ if (isBinary) {
+ rawData = Base64.decode(data, Base64.DEFAULT);
+ } else {
+ rawData = data.getBytes();
+ }
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
FileOutputStream out = new FileOutputStream(filename, append);
byte buff[] = new byte[rawData.length];