You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/07/08 20:45:06 UTC
[1/4] git commit: CB-6928: Handle 304 status code
Repository: cordova-plugin-file-transfer
Updated Branches:
refs/heads/master 4e5f10c3a -> 78453b5d1
CB-6928: Handle 304 status code
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/b88584c5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/b88584c5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/b88584c5
Branch: refs/heads/master
Commit: b88584c5a3f874f975942ca5c9509526d63825af
Parents: 22f1ea5
Author: Javier Puerto <ja...@becompany.ch>
Authored: Thu Jun 19 02:20:51 2014 +0200
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jul 8 14:14:12 2014 -0400
----------------------------------------------------------------------
src/android/FileTransfer.java | 142 ++++++++++++++++++++-----------------
www/FileTransferError.js | 1 +
2 files changed, 79 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/b88584c5/src/android/FileTransfer.java
----------------------------------------------------------------------
diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index 2b1a2f0..c757c99 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -76,6 +76,7 @@ public class FileTransfer extends CordovaPlugin {
public static int INVALID_URL_ERR = 2;
public static int CONNECTION_ERR = 3;
public static int ABORTED_ERR = 4;
+ public static int NOT_MODIFIED_ERR = 5;
private static HashMap<String, RequestContext> activeRequests = new HashMap<String, RequestContext>();
private static final int MAX_BUFFER_SIZE = 16 * 1024;
@@ -712,6 +713,7 @@ public class FileTransfer extends CordovaPlugin {
File file = null;
PluginResult result = null;
TrackingInputStream inputStream = null;
+ boolean cached = false;
OutputStream outputStream = null;
try {
@@ -763,79 +765,91 @@ public class FileTransfer extends CordovaPlugin {
}
connection.connect();
-
- if (connection.getContentEncoding() == null || connection.getContentEncoding().equalsIgnoreCase("gzip")) {
- // Only trust content-length header if we understand
- // the encoding -- identity or gzip
- if (connection.getContentLength() != -1) {
- progress.setLengthComputable(true);
- progress.setTotal(connection.getContentLength());
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
+ cached = true;
+ connection.disconnect();
+ Log.d(LOG_TAG, "Resource not modified: " + source);
+ JSONObject error = createFileTransferError(NOT_MODIFIED_ERR, source, target, connection, null);
+ result = new PluginResult(PluginResult.Status.ERROR, error);
+ } else {
+ if (connection.getContentEncoding() == null || connection.getContentEncoding().equalsIgnoreCase("gzip")) {
+ // Only trust content-length header if we understand
+ // the encoding -- identity or gzip
+ if (connection.getContentLength() != -1) {
+ progress.setLengthComputable(true);
+ progress.setTotal(connection.getContentLength());
+ }
}
+ inputStream = getInputStream(connection);
}
- inputStream = getInputStream(connection);
}
-
- try {
- synchronized (context) {
- if (context.aborted) {
- return;
+
+ if (!cached) {
+ try {
+ synchronized (context) {
+ if (context.aborted) {
+ return;
+ }
+ context.connection = connection;
}
- context.connection = connection;
- }
-
- // write bytes to file
- byte[] buffer = new byte[MAX_BUFFER_SIZE];
- int bytesRead = 0;
- outputStream = resourceApi.openOutputStream(targetUri);
- while ((bytesRead = inputStream.read(buffer)) > 0) {
- outputStream.write(buffer, 0, bytesRead);
- // Send a progress event.
- progress.setLoaded(inputStream.getTotalRawBytesRead());
- PluginResult progressResult = new PluginResult(PluginResult.Status.OK, progress.toJSONObject());
- progressResult.setKeepCallback(true);
- context.sendPluginResult(progressResult);
- }
- } finally {
- synchronized (context) {
- context.connection = null;
+
+ // write bytes to file
+ byte[] buffer = new byte[MAX_BUFFER_SIZE];
+ int bytesRead = 0;
+ outputStream = resourceApi.openOutputStream(targetUri);
+ while ((bytesRead = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, bytesRead);
+ // Send a progress event.
+ progress.setLoaded(inputStream.getTotalRawBytesRead());
+ PluginResult progressResult = new PluginResult(PluginResult.Status.OK, progress.toJSONObject());
+ progressResult.setKeepCallback(true);
+ context.sendPluginResult(progressResult);
+ }
+ } finally {
+ synchronized (context) {
+ context.connection = null;
+ }
+ safeClose(inputStream);
+ safeClose(outputStream);
}
- safeClose(inputStream);
- safeClose(outputStream);
- }
-
- Log.d(LOG_TAG, "Saved file: " + target);
-
- // create FileEntry object
- Class webViewClass = webView.getClass();
- PluginManager pm = null;
- try {
- Method gpm = webViewClass.getMethod("getPluginManager");
- pm = (PluginManager) gpm.invoke(webView);
- } catch (NoSuchMethodException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- }
- if (pm == null) {
+
+ Log.d(LOG_TAG, "Saved file: " + target);
+
+
+ // create FileEntry object
+ Class webViewClass = webView.getClass();
+ PluginManager pm = null;
try {
- Field pmf = webViewClass.getField("pluginManager");
- pm = (PluginManager)pmf.get(webView);
- } catch (NoSuchFieldException e) {
+ Method gpm = webViewClass.getMethod("getPluginManager");
+ pm = (PluginManager) gpm.invoke(webView);
+ } catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
}
- }
- FileUtils filePlugin = (FileUtils) pm.getPlugin("File");
- if (filePlugin != null) {
- JSONObject fileEntry = filePlugin.getEntryForFile(file);
- if (fileEntry != null) {
- result = new PluginResult(PluginResult.Status.OK, fileEntry);
+ if (pm == null) {
+ try {
+ Field pmf = webViewClass.getField("pluginManager");
+ pm = (PluginManager)pmf.get(webView);
+ } catch (NoSuchFieldException e) {
+ } catch (IllegalAccessException e) {
+ }
+ }
+ file = resourceApi.mapUriToFile(targetUri);
+ context.targetFile = file;
+ FileUtils filePlugin = (FileUtils) pm.getPlugin("File");
+ if (filePlugin != null) {
+ JSONObject fileEntry = filePlugin.getEntryForFile(file);
+ if (fileEntry != null) {
+ result = new PluginResult(PluginResult.Status.OK, fileEntry);
+ } else {
+ JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, null);
+ Log.e(LOG_TAG, "File plugin cannot represent download path");
+ result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
+ }
} else {
- JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, null);
- Log.e(LOG_TAG, "File plugin cannot represent download path");
- result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
+ Log.e(LOG_TAG, "File plugin not found; cannot save downloaded file");
+ result = new PluginResult(PluginResult.Status.ERROR, "File plugin not found; cannot save downloaded file");
}
- } else {
- Log.e(LOG_TAG, "File plugin not found; cannot save downloaded file");
- result = new PluginResult(PluginResult.Status.ERROR, "File plugin not found; cannot save downloaded file");
}
} catch (FileNotFoundException e) {
@@ -871,7 +885,7 @@ public class FileTransfer extends CordovaPlugin {
result = new PluginResult(PluginResult.Status.ERROR, createFileTransferError(CONNECTION_ERR, source, target, connection, null));
}
// Remove incomplete download.
- if (result.getStatus() != PluginResult.Status.OK.ordinal() && file != null) {
+ if (!cached && result.getStatus() != PluginResult.Status.OK.ordinal() && file != null) {
file.delete();
}
context.sendPluginResult(result);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/b88584c5/www/FileTransferError.js
----------------------------------------------------------------------
diff --git a/www/FileTransferError.js b/www/FileTransferError.js
index 1394f59..7121882 100644
--- a/www/FileTransferError.js
+++ b/www/FileTransferError.js
@@ -35,5 +35,6 @@ FileTransferError.FILE_NOT_FOUND_ERR = 1;
FileTransferError.INVALID_URL_ERR = 2;
FileTransferError.CONNECTION_ERR = 3;
FileTransferError.ABORT_ERR = 4;
+FileTransferError.NOT_MODIFIED_ERR = 5;
module.exports = FileTransferError;
[2/4] git commit: CB-6928: Open output stream only if it's necessary.
Posted by ia...@apache.org.
CB-6928: Open output stream only if it's necessary.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/22f1ea57
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/22f1ea57
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/22f1ea57
Branch: refs/heads/master
Commit: 22f1ea573c4eadf784b7731fc4a4d815fa0a067b
Parents: 4e5f10c
Author: Javier Puerto <ja...@becompany.ch>
Authored: Thu Jun 12 10:34:42 2014 +0200
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jul 8 14:14:12 2014 -0400
----------------------------------------------------------------------
src/android/FileTransfer.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/22f1ea57/src/android/FileTransfer.java
----------------------------------------------------------------------
diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index c04c0d3..2b1a2f0 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -716,7 +716,6 @@ public class FileTransfer extends CordovaPlugin {
OutputStream outputStream = null;
try {
OpenForReadResult readResult = null;
- outputStream = resourceApi.openOutputStream(targetUri);
file = resourceApi.mapUriToFile(targetUri);
context.targetFile = file;
@@ -787,6 +786,7 @@ public class FileTransfer extends CordovaPlugin {
// write bytes to file
byte[] buffer = new byte[MAX_BUFFER_SIZE];
int bytesRead = 0;
+ outputStream = resourceApi.openOutputStream(targetUri);
while ((bytesRead = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, bytesRead);
// Send a progress event.
@@ -854,7 +854,6 @@ public class FileTransfer extends CordovaPlugin {
Log.e(LOG_TAG, error.toString(), e);
result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
} finally {
- safeClose(outputStream);
synchronized (activeRequests) {
activeRequests.remove(objectId);
}
[3/4] git commit: CB-6928: Add new error code to documentation
Posted by ia...@apache.org.
CB-6928: Add new error code to documentation
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/97a831e5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/97a831e5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/97a831e5
Branch: refs/heads/master
Commit: 97a831e568d555e776c078f40fb3ea7bf4fbdf23
Parents: b88584c
Author: Javier Puerto <ja...@becompany.ch>
Authored: Thu Jun 19 10:52:34 2014 +0200
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jul 8 14:14:13 2014 -0400
----------------------------------------------------------------------
doc/es/index.md | 3 ++-
doc/fr/index.md | 3 ++-
doc/index.md | 1 +
doc/it/index.md | 3 ++-
doc/ja/index.md | 3 ++-
doc/ko/index.md | 3 ++-
doc/pl/index.md | 1 +
doc/zh/index.md | 3 ++-
8 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/es/index.md
----------------------------------------------------------------------
diff --git a/doc/es/index.md b/doc/es/index.md
index fdf8e59..889fdf3 100644
--- a/doc/es/index.md
+++ b/doc/es/index.md
@@ -260,6 +260,7 @@ A `FileTransferError` objeto se pasa a un callback de error cuando se produce un
* 2 = `FileTransferError.INVALID_URL_ERR`
* 3 = `FileTransferError.CONNECTION_ERR`
* 4 = `FileTransferError.ABORT_ERR`
+* 5 = `FileTransferError.NOT_MODIFIED_ERR`
## Al revés notas de compatibilidad
@@ -280,4 +281,4 @@ Si va a actualizar a una nueva (1.0.0 o más reciente) versión del archivo y pr
cdvfile://localhost/persistent/path/to/file
-que puede ser utilizado en lugar de la ruta del archivo absoluta tanto en `download()` y `upload()` los métodos.
\ No newline at end of file
+que puede ser utilizado en lugar de la ruta del archivo absoluta tanto en `download()` y `upload()` los métodos.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/fr/index.md
----------------------------------------------------------------------
diff --git a/doc/fr/index.md b/doc/fr/index.md
index c9abc6a..e6b08cb 100644
--- a/doc/fr/index.md
+++ b/doc/fr/index.md
@@ -260,6 +260,7 @@ Un objet `FileTransferError` est passé à une callback d'erreur lorsqu'une erre
* 2 = `FileTransferError.INVALID_URL_ERR`
* 3 = `FileTransferError.CONNECTION_ERR`
* 4 = `FileTransferError.ABORT_ERR`
+* 5 = `FileTransferError.NOT_MODIFIED_ERR`
## Backwards Compatibility Notes
@@ -280,4 +281,4 @@ Si vous migrez vers une nouvelle version du fichier (1.0.0 ou plus récent) et q
cdvfile://localhost/persistent/path/to/file
-qui peut être utilisé à la place du chemin d'accès absolu au fichier dans les méthodes `download()` et `upload()`.
\ No newline at end of file
+qui peut être utilisé à la place du chemin d'accès absolu au fichier dans les méthodes `download()` et `upload()`.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index ec1d1b8..997d273 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -257,6 +257,7 @@ A `FileTransferError` object is passed to an error callback when an error occurs
- 2 = `FileTransferError.INVALID_URL_ERR`
- 3 = `FileTransferError.CONNECTION_ERR`
- 4 = `FileTransferError.ABORT_ERR`
+- 5 = `FileTransferError.NOT_MODIFIED_ERR`
## Backwards Compatibility Notes
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/it/index.md
----------------------------------------------------------------------
diff --git a/doc/it/index.md b/doc/it/index.md
index ed74c91..c9ea0d8 100644
--- a/doc/it/index.md
+++ b/doc/it/index.md
@@ -260,6 +260,7 @@ A `FileTransferError` oggetto viene passato a un callback di errore quando si ve
* 2 = `FileTransferError.INVALID_URL_ERR`
* 3 = `FileTransferError.CONNECTION_ERR`
* 4 = `FileTransferError.ABORT_ERR`
+* 5 = `FileTransferError.NOT_MODIFIED_ERR`
## Note di compatibilità all'indietro
@@ -280,4 +281,4 @@ Se si esegue l'aggiornamento a una nuova (1.0.0 o più recente) precedentemente
cdvfile://localhost/persistent/path/to/file
-che può essere utilizzato al posto del percorso assoluto in entrambi `download()` e `upload()` metodi.
\ No newline at end of file
+che può essere utilizzato al posto del percorso assoluto in entrambi `download()` e `upload()` metodi.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/ja/index.md
----------------------------------------------------------------------
diff --git a/doc/ja/index.md b/doc/ja/index.md
index f979fff..1a2da1c 100644
--- a/doc/ja/index.md
+++ b/doc/ja/index.md
@@ -260,6 +260,7 @@ A `FileTransferError` オブジェクトは、エラーが発生エラー コー
* 2 = `FileTransferError.INVALID_URL_ERR`
* 3 = `FileTransferError.CONNECTION_ERR`
* 4 = `FileTransferError.ABORT_ERR`
+* 5 = `FileTransferError.NOT_MODIFIED_ERR`
## 後方互換性をノートします。
@@ -280,4 +281,4 @@ A `FileTransferError` オブジェクトは、エラーが発生エラー コー
cdvfile://localhost/persistent/path/to/file
-両方のファイルの絶対パスの代わりに使用できる `download()` および `upload()` メソッド。
\ No newline at end of file
+両方のファイルの絶対パスの代わりに使用できる `download()` および `upload()` メソッド。
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/ko/index.md
----------------------------------------------------------------------
diff --git a/doc/ko/index.md b/doc/ko/index.md
index 55d8dcf..138c326 100644
--- a/doc/ko/index.md
+++ b/doc/ko/index.md
@@ -260,6 +260,7 @@ A `FileTransferError` 오류가 발생 하면 오류 콜백 개체 전달 됩니
* 2 = `FileTransferError.INVALID_URL_ERR`
* 3 = `FileTransferError.CONNECTION_ERR`
* 4 = `FileTransferError.ABORT_ERR`
+* 5 = `FileTransferError.NOT_MODIFIED_ERR`
## 이전 버전과 호환성 노트
@@ -280,4 +281,4 @@ A `FileTransferError` 오류가 발생 하면 오류 콜백 개체 전달 됩니
cdvfile://localhost/persistent/path/to/file
-둘 다에서 절대 파일 경로 대신 사용할 수 있는 `download()` 및 `upload()` 메서드.
\ No newline at end of file
+둘 다에서 절대 파일 경로 대신 사용할 수 있는 `download()` 및 `upload()` 메서드.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/pl/index.md
----------------------------------------------------------------------
diff --git a/doc/pl/index.md b/doc/pl/index.md
index 32829af..4860969 100644
--- a/doc/pl/index.md
+++ b/doc/pl/index.md
@@ -258,6 +258,7 @@ A `FileTransferError` obiekt jest przekazywany do wywołania zwrotnego błąd, g
* `FileTransferError.INVALID_URL_ERR`
* `FileTransferError.CONNECTION_ERR`
* `FileTransferError.ABORT_ERR`
+* `FileTransferError.NOT_MODIFIED_ERR`
## Do tyłu zgodności stwierdza
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/97a831e5/doc/zh/index.md
----------------------------------------------------------------------
diff --git a/doc/zh/index.md b/doc/zh/index.md
index 0a277d9..74d5bc8 100644
--- a/doc/zh/index.md
+++ b/doc/zh/index.md
@@ -260,6 +260,7 @@ A `FileTransferError` 物件傳遞到錯誤回檔時出現錯誤。
* 2 = `FileTransferError.INVALID_URL_ERR`
* 3 = `FileTransferError.CONNECTION_ERR`
* 4 = `FileTransferError.ABORT_ERR`
+* 5 = `FileTransferError.NOT_MODIFIED_ERR`
## 向後相容性注意到
@@ -280,4 +281,4 @@ A `FileTransferError` 物件傳遞到錯誤回檔時出現錯誤。
cdvfile://localhost/persistent/path/to/file
-可以使用在中兩者的絕對檔路徑位置 `download()` 和 `upload()` 方法。
\ No newline at end of file
+可以使用在中兩者的絕對檔路徑位置 `download()` 和 `upload()` 方法。
[4/4] git commit: Merge branch 'CB-6928' (This closes #32)
Posted by ia...@apache.org.
Merge branch 'CB-6928' (This closes #32)
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/78453b5d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/78453b5d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/78453b5d
Branch: refs/heads/master
Commit: 78453b5d155548266944c2ce15d10ace74878a14
Parents: 4e5f10c 97a831e
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jul 8 14:22:45 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jul 8 14:22:45 2014 -0400
----------------------------------------------------------------------
doc/es/index.md | 3 +-
doc/fr/index.md | 3 +-
doc/index.md | 1 +
doc/it/index.md | 3 +-
doc/ja/index.md | 3 +-
doc/ko/index.md | 3 +-
doc/pl/index.md | 1 +
doc/zh/index.md | 3 +-
src/android/FileTransfer.java | 143 ++++++++++++++++++++-----------------
www/FileTransferError.js | 1 +
10 files changed, 93 insertions(+), 71 deletions(-)
----------------------------------------------------------------------