cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [1/2] webworks commit: [CB-2646] added fileSize method to file utilities
Date Thu, 21 Mar 2013 22:02:36 GMT
Updated Branches:
  refs/heads/master 1e9e95ad5 -> e50fcd5ad


[CB-2646] added fileSize method to file utilities


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/3dba2eda
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/3dba2eda
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/3dba2eda

Branch: refs/heads/master
Commit: 3dba2edaa9a34d70f1110c27d8c54c2c7fe2925c
Parents: 1e9e95a
Author: lorinbeer <lorin@adobe.com>
Authored: Thu Mar 21 14:23:06 2013 -0700
Committer: lorinbeer <lorin@adobe.com>
Committed: Thu Mar 21 14:23:06 2013 -0700

----------------------------------------------------------------------
 .../ext/src/org/apache/cordova/util/FileUtils.java |   22 ++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/3dba2eda/framework/ext/src/org/apache/cordova/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/ext/src/org/apache/cordova/util/FileUtils.java b/framework/ext/src/org/apache/cordova/util/FileUtils.java
index 622bf48..6ca1ffe 100644
--- a/framework/ext/src/org/apache/cordova/util/FileUtils.java
+++ b/framework/ext/src/org/apache/cordova/util/FileUtils.java
@@ -228,7 +228,7 @@ public class FileUtils {
     public static void mkdir(String dirPath) throws IOException {
         FileConnection fconn = null;
         try {
-            fconn = (FileConnection)Connector.open(dirPath);
+            fconn = (FileConnection)Connector.open(dirPath, Connector.READ);
             if (fconn.isDirectory()) {
                 // nothing to do
                 return;
@@ -248,6 +248,26 @@ public class FileUtils {
     }
 
     /**
+     * Determines the size of a file on the file system. Size always represents number of
bytes contained in the file; never pre-allocated but empty space
+     * @return size in bytes of the selected file, or -1 if the file does not exist or is
inaccessible
+     */
+    public static long fileSize(String path) throws IOException {
+        FileConnection fconn = null;
+        long fsize = -1;
+        try {
+            fconn = (FileConnection)Connector.open(path);
+            fsize = fconn.fileSize();
+        } catch (IOException e) {
+            Logger.log(FileUtils.class.getName() + " fileSize:  " + path + "not found or
inaccessible");
+        } finally {
+            try {
+                if (fconn != null) fconn.close();
+            } catch (IOException ignored) {}
+        }
+       return fsize;
+    }
+
+    /**
      * Copies a file or directory to a new location. If copying a directory, the
      * entire contents of the directory are copied recursively.
      *


Mime
View raw message