incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: Set the total field for FileTransfer upload progress events.
Date Mon, 24 Sep 2012 15:55:23 GMT
Updated Branches:
  refs/heads/master 6e1fdc77a -> fed368d55


Set the total field for FileTransfer upload progress events.

This also removes an incorrect assumption that content: InputStreams
will be FileInputStreams.


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/fed368d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/fed368d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/fed368d5

Branch: refs/heads/master
Commit: fed368d553b1823b4a4b9c7400e096073bd53af1
Parents: 6e1fdc7
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Sep 24 11:50:55 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Sep 24 11:50:55 2012 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileTransfer.java |   20 +++++++++-----
 1 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/fed368d5/framework/src/org/apache/cordova/FileTransfer.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java
index 72adc91..1917d8a 100644
--- a/framework/src/org/apache/cordova/FileTransfer.java
+++ b/framework/src/org/apache/cordova/FileTransfer.java
@@ -187,7 +187,7 @@ public class FileTransfer extends Plugin {
             FileProgressResult progress = new FileProgressResult();
 
             // Get a input stream of the file on the phone
-            FileInputStream fileInputStream = (FileInputStream) getPathFromUri(source);
+            InputStream inputStream = getPathFromUri(source);
 
             DataOutputStream dos = null;
 
@@ -295,12 +295,18 @@ public class FileTransfer extends Plugin {
 
             int stringLength = extraBytes.length + midParams.length() + tailParams.length()
+ fileNameBytes.length;
             Log.d(LOG_TAG, "String Length: " + stringLength);
-            int fixedLength = (int) fileInputStream.getChannel().size() + stringLength;
+            int fixedLength = -1;
+            if (inputStream instanceof FileInputStream) {
+                fixedLength = (int) ((FileInputStream)inputStream).getChannel().size() +
stringLength;
+                progress.setLengthComputable(true);
+                progress.setTotal(fixedLength);
+            }
             Log.d(LOG_TAG, "Content Length: " + fixedLength);
             // setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
             // http://code.google.com/p/android/issues/detail?id=3164
             // It also causes OOM if HTTPS is used, even on newer devices.
             chunkedMode = chunkedMode && (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO
|| useHttps);
+            chunkedMode = chunkedMode || (fixedLength == -1);
             		
             if (chunkedMode) {
                 conn.setChunkedStreamingMode(maxBufferSize);
@@ -318,12 +324,12 @@ public class FileTransfer extends Plugin {
             dos.writeBytes(midParams);
 
             // create a buffer of maximum size
-            bytesAvailable = fileInputStream.available();
+            bytesAvailable = inputStream.available();
             bufferSize = Math.min(bytesAvailable, maxBufferSize);
             buffer = new byte[bufferSize];
 
             // read file and write it into form...
-            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
+            bytesRead = inputStream.read(buffer, 0, bufferSize);
             totalBytes = 0;
 
             long prevBytesRead = 0;
@@ -335,9 +341,9 @@ public class FileTransfer extends Plugin {
                 	prevBytesRead = totalBytes;
                 	Log.d(LOG_TAG, "Uploaded " + totalBytes + " of " + fixedLength + " bytes");
                 }
-                bytesAvailable = fileInputStream.available();
+                bytesAvailable = inputStream.available();
                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
-                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
+                bytesRead = inputStream.read(buffer, 0, bufferSize);
                 if (objectId != null) {
                     // Only send progress callbacks if the JS code sent us an object ID,
                     // so we don't spam old versions with unrecognized callbacks.
@@ -358,7 +364,7 @@ public class FileTransfer extends Plugin {
             dos.writeBytes(tailParams);
 
             // close streams
-            fileInputStream.close();
+            inputStream.close();
             dos.flush();
             dos.close();
 


Mime
View raw message