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/06/12 23:36:41 UTC
[1/2] git commit: CB-2406: Moving Ian Clelland's Binary Data support
to FileUtils.java
Updated Branches:
refs/heads/master e58827dbb -> 841c9e577
CB-2406: Moving Ian Clelland's Binary Data support to FileUtils.java
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/5ecbfab4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5ecbfab4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5ecbfab4
Branch: refs/heads/master
Commit: 5ecbfab49b92ede97b45d2fcdfb6031d6de96810
Parents: d028838
Author: Joe Bowser <bo...@apache.org>
Authored: Wed Jun 12 13:33:51 2013 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Jun 12 13:33:51 2013 -0700
----------------------------------------------------------------------
src/android/FileUtils.java | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5ecbfab4/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 2939691..5850881 100755
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -15,17 +15,16 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-*/
+ */
package org.apache.cordova.core;
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.commons.codec.binary.Base64;
-import org.apache.cordova.DirectoryManager;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
@@ -135,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")) {
@@ -951,7 +950,7 @@ public class FileUtils extends CordovaPlugin {
break;
default: // Base64.
String contentType = FileHelper.getMimeType(filename, cordova);
- byte[] base64 = Base64.encodeBase64(bytes);
+ byte[] base64 = Base64.encode(bytes, Base64.DEFAULT);
String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
result = new PluginResult(PluginResult.Status.OK, s);
}
@@ -1000,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");
}
@@ -1017,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];
[2/2] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/cordova-plugin-file
Posted by bo...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-file
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/841c9e57
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/841c9e57
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/841c9e57
Branch: refs/heads/master
Commit: 841c9e5774d49f66ebf2416c10aaf84e2c3656eb
Parents: 5ecbfab e58827d
Author: Joe Bowser <bo...@apache.org>
Authored: Wed Jun 12 14:36:31 2013 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Jun 12 14:36:31 2013 -0700
----------------------------------------------------------------------
plugin.xml | 89 ++-
src/ios/CDVFile.h | 106 +++
src/ios/CDVFile.m | 1414 +++++++++++++++++++++++++++++++++
www/DirectoryEntry.js | 106 +++
www/DirectoryReader.js | 63 ++
www/Entry.js | 220 +++++
www/File.js | 77 ++
www/FileEntry.js | 80 ++
www/FileError.js | 46 ++
www/FileReader.js | 387 +++++++++
www/FileSystem.js | 38 +
www/FileUploadOptions.js | 41 +
www/FileUploadResult.js | 32 +
www/FileWriter.js | 274 +++++++
www/Flags.js | 36 +
www/LocalFileSystem.js | 34 +
www/Metadata.js | 31 +
www/ProgressEvent.js | 67 ++
www/ios/Entry.js | 32 +
www/requestFileSystem.js | 61 ++
www/resolveLocalFileSystemURI.js | 64 ++
21 files changed, 3296 insertions(+), 2 deletions(-)
----------------------------------------------------------------------