From: David A. Velasco Date: Mon, 20 Jan 2014 08:24:12 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/oc_framework_cleanup_and_documentation' into... X-Git-Tag: oc-android-1.5.5~69^2~14 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/1fd16efe798eced749e05eddf0fc0508a13ab926?hp=-c Merge remote-tracking branch 'origin/oc_framework_cleanup_and_documentation' into oc_framework_cleanup_and_documentation --- 1fd16efe798eced749e05eddf0fc0508a13ab926 diff --combined oc_framework/sample_client/src/com/owncloud/android/oc_framework/sampleclient/MainActivity.java index ad2b4dd5,847be9e0..79d273a0 --- a/oc_framework/sample_client/src/com/owncloud/android/oc_framework/sampleclient/MainActivity.java +++ b/oc_framework/sample_client/src/com/owncloud/android/oc_framework/sampleclient/MainActivity.java @@@ -1,3 -1,27 +1,27 @@@ + /* ownCloud Android Library is available under MIT license + * Copyright (C) 2014 ownCloud (http://www.owncloud.org/) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + package com.owncloud.android.oc_framework.sampleclient; import java.io.File; @@@ -146,7 -170,9 +170,7 @@@ public class MainActivity extends Activ File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File fileToUpload = upFolder.listFiles()[0]; String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); - RemoteFile rFileToDownload = new RemoteFile(remotePath); - rFileToDownload.setLength(fileToUpload.length()); - DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(rFileToDownload, downFolder.getAbsolutePath()); + DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath()); downloadOperation.addDatatransferProgressListener(this); downloadOperation.execute(mClient, this, mHandler); } diff --combined oc_framework/src/com/owncloud/android/oc_framework/operations/remote/DownloadRemoteFileOperation.java index 5103c562,1f2522a1..6d90e629 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/DownloadRemoteFileOperation.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/DownloadRemoteFileOperation.java @@@ -1,17 -1,24 +1,24 @@@ - /* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + /* ownCloud Android Library is available under MIT license + * Copyright (C) 2014 ownCloud (http://www.owncloud.org/) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. * */ @@@ -21,6 -28,7 +28,6 @@@ import java.io.BufferedInputStream import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@@ -37,6 -45,7 +44,6 @@@ import com.owncloud.android.oc_framewor import com.owncloud.android.oc_framework.network.webdav.WebdavClient; import com.owncloud.android.oc_framework.network.webdav.WebdavUtils; import com.owncloud.android.oc_framework.operations.OperationCancelledException; -import com.owncloud.android.oc_framework.operations.RemoteFile; import com.owncloud.android.oc_framework.operations.RemoteOperation; import com.owncloud.android.oc_framework.operations.RemoteOperationResult; @@@ -53,15 -62,15 +60,15 @@@ public class DownloadRemoteFileOperatio private Set mDataTransferListeners = new HashSet(); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); - private long mModificationTimestamp = 0; + //private long mModificationTimestamp = 0; private GetMethod mGet; - private RemoteFile mRemoteFile; - private String mTemporalFolder; + private String mRemotePath; + private String mDownloadFolderPath; - public DownloadRemoteFileOperation(RemoteFile remoteFile, String temporalFolder) { - mRemoteFile = remoteFile; - mTemporalFolder = temporalFolder; + public DownloadRemoteFileOperation(String remotePath, String downloadFolderPath) { + mRemotePath = remotePath; + mDownloadFolderPath = downloadFolderPath; } @Override @@@ -76,11 -85,11 +83,11 @@@ tmpFile.getParentFile().mkdirs(); int status = downloadFile(client, tmpFile); result = new RemoteOperationResult(isSuccess(status), status, (mGet != null ? mGet.getResponseHeaders() : null)); - Log.i(TAG, "Download of " + mRemoteFile.getRemotePath() + " to " + getTmpPath() + ": " + result.getLogMessage()); + Log.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult(e); - Log.e(TAG, "Download of " + mRemoteFile.getRemotePath() + " to " + getTmpPath() + ": " + result.getLogMessage(), e); + Log.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage(), e); } return result; @@@ -90,7 -99,7 +97,7 @@@ protected int downloadFile(WebdavClient client, File targetFile) throws HttpException, IOException, OperationCancelledException { int status = -1; boolean savedFile = false; - mGet = new GetMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemoteFile.getRemotePath())); + mGet = new GetMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath)); Iterator it = null; FileOutputStream fos = null; @@@ -101,9 -110,6 +108,9 @@@ BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream()); fos = new FileOutputStream(targetFile); long transferred = 0; + + Header contentLength = mGet.getResponseHeader("Content-Length"); + long totalToTransfer = (contentLength != null && contentLength.getValue().length() >0) ? Long.parseLong(contentLength.getValue()) : 0; byte[] bytes = new byte[4096]; int readResult = 0; @@@ -119,18 -125,16 +126,18 @@@ synchronized (mDataTransferListeners) { it = mDataTransferListeners.iterator(); while (it.hasNext()) { - it.next().onTransferProgress(readResult, transferred, mRemoteFile.getLength(), targetFile.getName()); + it.next().onTransferProgress(readResult, transferred, totalToTransfer, targetFile.getName()); } } } savedFile = true; + /* Header modificationTime = mGet.getResponseHeader("Last-Modified"); if (modificationTime != null) { Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); mModificationTimestamp = (d != null) ? d.getTime() : 0; } + */ } else { client.exhaustResponse(mGet.getResponseBodyAsStream()); @@@ -151,7 -155,7 +158,7 @@@ } private String getTmpPath() { - return mTemporalFolder + mRemoteFile.getRemotePath(); + return mDownloadFolderPath + mRemotePath; } public void addDatatransferProgressListener (OnDatatransferProgressListener listener) {