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 2012/02/20 22:01:00 UTC

[2/21] android commit: more file:// URI truncation :D

more file:// URI truncation :D


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/42430d5d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/42430d5d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/42430d5d

Branch: refs/heads/master
Commit: 42430d5d1115c2923f8321c2f4ad21511c3e1716
Parents: 770a257
Author: Fil Maj <fi...@nitobi.com>
Authored: Fri Feb 17 11:40:22 2012 -0800
Committer: Joe Bowser <bo...@apache.org>
Committed: Mon Feb 20 11:04:37 2012 -0800

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileUtils.java |   28 +++++++++++------
 1 files changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/42430d5d/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 51fc4ab..7dbf905 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -932,8 +932,8 @@ public class FileUtils extends Plugin {
      */
     public String readAsDataURL(String filename) throws FileNotFoundException, IOException {
         byte[] bytes = new byte[1000];
-           BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
-           ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
         int numRead = 0;
         while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
             bos.write(bytes, 0, numRead);
@@ -975,20 +975,24 @@ public class FileUtils extends Plugin {
      */
     /**/
     public long write(String filename, String data, int offset) throws FileNotFoundException, IOException {
+        if (filename.startsWith("file://")) {
+            filename = filename.substring(7);
+        }
+
         boolean append = false;
         if (offset > 0) {
             this.truncateFile(filename, offset);
             append = true;
         }
 
-           byte [] 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();
+       byte [] 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();
 
         return data.length();
     }
@@ -1001,6 +1005,10 @@ public class FileUtils extends Plugin {
      * @throws FileNotFoundException, IOException
      */
     private long truncateFile(String filename, long size) throws FileNotFoundException, IOException {
+        if (filename.startsWith("file://")) {
+            filename = filename.substring(7);
+        }
+
         RandomAccessFile raf = new RandomAccessFile(filename, "rw");
 
         if (raf.length() >= size) {