You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/10/02 17:45:41 UTC
[2/3] android commit: More tweaks to FileTransfer.
More tweaks to FileTransfer.
Some clean-up and moved IO out of critical sections.
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/ca9539b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/ca9539b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/ca9539b5
Branch: refs/heads/master
Commit: ca9539b5b6a1106d02313ef555abd635aec3b69b
Parents: ff25be8
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Oct 2 11:24:52 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Oct 2 11:45:20 2012 -0400
----------------------------------------------------------------------
framework/src/org/apache/cordova/FileTransfer.java | 29 +++++++--------
1 files changed, 13 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ca9539b5/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 dd26629..9c053ad 100644
--- a/framework/src/org/apache/cordova/FileTransfer.java
+++ b/framework/src/org/apache/cordova/FileTransfer.java
@@ -347,11 +347,11 @@ public class FileTransfer extends CordovaPlugin {
DataOutputStream dos = null;
try {
+ dos = new DataOutputStream( conn.getOutputStream() );
synchronized (context) {
if (context.aborted) {
- throw new IOException("Request aborted");
+ return;
}
- dos = new DataOutputStream( conn.getOutputStream() );
context.currentOutputStream = dos;
}
//We don't want to change encoding, we just want this to write for all Unicode.
@@ -402,11 +402,11 @@ public class FileTransfer extends CordovaPlugin {
int responseCode = conn.getResponseCode();
InputStream inStream = null;
try {
+ inStream = getInputStream(conn);
synchronized (context) {
if (context.aborted) {
- throw new IOException("Request aborted");
+ return;
}
- inStream = getInputStream(conn);
context.currentInputStream = inStream;
}
@@ -420,6 +420,7 @@ public class FileTransfer extends CordovaPlugin {
}
responseString = out.toString("UTF-8");
} finally {
+ context.currentInputStream = null;
safeClose(inStream);
}
@@ -429,10 +430,6 @@ public class FileTransfer extends CordovaPlugin {
// send request and retrieve response
result.setResponseCode(responseCode);
result.setResponse(responseString);
- context.currentInputStream = null;
- synchronized (activeRequests) {
- activeRequests.remove(objectId);
- }
context.sendPluginResult(new PluginResult(PluginResult.Status.OK, result.toJSONObject()));
} catch (FileNotFoundException e) {
@@ -475,12 +472,11 @@ public class FileTransfer extends CordovaPlugin {
try {
stream.close();
} catch (IOException e) {
- e.printStackTrace();
}
}
}
- private InputStream getInputStream(HttpURLConnection conn) throws IOException {
+ private static InputStream getInputStream(HttpURLConnection conn) throws IOException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
return new DoneHandlerInputStream(conn.getInputStream());
}
@@ -488,7 +484,7 @@ public class FileTransfer extends CordovaPlugin {
}
// always verify the host - don't check for certificate
- final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
+ private final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
@@ -533,7 +529,7 @@ public class FileTransfer extends CordovaPlugin {
}
}
- private JSONObject createFileTransferError(int errorCode, String source, String target, HttpURLConnection connection) {
+ private static JSONObject createFileTransferError(int errorCode, String source, String target, HttpURLConnection connection) {
Integer httpStatus = null;
@@ -553,7 +549,7 @@ public class FileTransfer extends CordovaPlugin {
* @param errorCode the error
* @return JSONObject containing the error
*/
- private JSONObject createFileTransferError(int errorCode, String source, String target, Integer httpStatus) {
+ private static JSONObject createFileTransferError(int errorCode, String source, String target, Integer httpStatus) {
JSONObject error = null;
try {
error = new JSONObject();
@@ -576,7 +572,7 @@ public class FileTransfer extends CordovaPlugin {
* @param defaultString the default to be used if the arg does not exist
* @return String with the retrieved value
*/
- private String getArgument(JSONArray args, int position, String defaultString) {
+ private static String getArgument(JSONArray args, int position, String defaultString) {
String arg = defaultString;
if (args.length() >= position) {
arg = args.optString(position);
@@ -686,11 +682,11 @@ public class FileTransfer extends CordovaPlugin {
InputStream inputStream = null;
try {
+ inputStream = getInputStream(connection);
synchronized (context) {
if (context.aborted) {
- throw new IOException("Request aborted");
+ return;
}
- inputStream = getInputStream(connection);
context.currentInputStream = inputStream;
}
@@ -708,6 +704,7 @@ public class FileTransfer extends CordovaPlugin {
context.sendPluginResult(progressResult);
}
} finally {
+ context.currentInputStream = null;
safeClose(inputStream);
safeClose(outputStream);
}