From b0fa6ae1d0eef8ed4aa8bb6840de834cba96c4b0 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 7 Aug 2018 17:24:19 +0200 Subject: [PATCH] Apply requested changes --- build.gradle | 3 - sample_client/AndroidManifest.xml | 30 ++-- .../android/lib/common/OwnCloudAccount.java | 5 +- .../android/lib/common/OwnCloudClient.java | 46 ++--- .../lib/common/OwnCloudClientFactory.java | 13 +- .../lib/common/OwnCloudClientManager.java | 6 +- .../lib/common/SingleSessionManager.java | 3 +- .../lib/common/accounts/AccountUtils.java | 38 ++-- .../oauth/BearerCredentials.java | 9 +- .../oauth/OAuth2GetAccessTokenOperation.java | 10 +- .../OAuth2RefreshAccessTokenOperation.java | 11 +- .../android/lib/common/http/HttpClient.java | 7 +- .../lib/common/http/HttpConstants.java | 1 + .../common/http/methods/HttpBaseMethod.java | 3 +- .../ChunkFromFileChannelRequestEntity.java | 165 ------------------ .../lib/common/network/FileRequestEntity.java | 93 ---------- .../common/operations/RemoteOperation.java | 19 +- .../operations/RemoteOperationResult.java | 24 +++ .../files/CopyRemoteFileOperation.java | 7 +- .../files/CreateRemoteFolderOperation.java | 4 +- .../files/DownloadRemoteFileOperation.java | 6 +- .../files/ExistenceCheckRemoteOperation.java | 4 +- .../lib/resources/files/FileUtils.java | 7 +- .../files/MoveRemoteFileOperation.java | 5 +- .../files/ReadRemoteFileOperation.java | 4 +- .../files/ReadRemoteFolderOperation.java | 1 - .../lib/resources/files/RemoteFile.java | 3 +- .../files/RenameRemoteFileOperation.java | 6 +- .../files/UploadRemoteFileOperation.java | 1 - .../ChunkedUploadRemoteFileOperation.java | 1 - .../RemoveRemoteChunksFolderOperation.java | 25 +++ .../resources/shares/ShareParserResult.java | 25 +++ .../ShareToRemoteOperationResultParser.java | 4 +- .../status/GetRemoteStatusOperation.java | 4 - .../users/GetRemoteUserAvatarOperation.java | 6 +- .../users/GetRemoteUserInfoOperation.java | 8 - .../SelfSignedConfidentSslSocketFactory.java | 8 +- .../lib/test_project/TestActivity.java | 2 +- 38 files changed, 188 insertions(+), 429 deletions(-) delete mode 100644 src/com/owncloud/android/lib/common/network/ChunkFromFileChannelRequestEntity.java delete mode 100644 src/com/owncloud/android/lib/common/network/FileRequestEntity.java diff --git a/build.gradle b/build.gradle index e6a9c02d..1d1e60d2 100644 --- a/build.gradle +++ b/build.gradle @@ -21,9 +21,6 @@ dependencies { api 'com.squareup.okhttp3:okhttp:3.10.0' api project(':dav4android') - // Used for network and database debuging - debugApi 'com.facebook.stetho:stetho:1.5.0' - debugApi 'com.facebook.stetho:stetho-okhttp3:1.5.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.51" } diff --git a/sample_client/AndroidManifest.xml b/sample_client/AndroidManifest.xml index c0885e36..58d5d6c1 100644 --- a/sample_client/AndroidManifest.xml +++ b/sample_client/AndroidManifest.xml @@ -24,23 +24,27 @@ --> - + package="com.owncloud.android.lib.sampleclient" + android:versionCode="1" + android:versionName="1.0"> + + - - + + - - + + - + \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/OwnCloudAccount.java b/src/com/owncloud/android/lib/common/OwnCloudAccount.java index 533247df..b3ebcd59 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudAccount.java +++ b/src/com/owncloud/android/lib/common/OwnCloudAccount.java @@ -116,9 +116,8 @@ public class OwnCloudAccount { * @throws IOException * @throws OperationCanceledException */ - public void loadCredentials(Context context) - throws AccountNotFoundException, AuthenticatorException, - IOException, OperationCanceledException { + public void loadCredentials(Context context) throws AuthenticatorException, + IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 3aba71d9..e05ccc30 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -25,36 +25,36 @@ package com.owncloud.android.lib.common; +import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountsException; +import android.accounts.AuthenticatorException; +import android.accounts.OperationCanceledException; import android.content.Context; import android.net.Uri; +import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.http.HttpClient; import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; -import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; - import java.io.IOException; import java.io.InputStream; import java.util.List; import at.bitfire.dav4android.exception.HttpException; -import at.bitfire.dav4android.exception.RedirectException; import okhttp3.Cookie; import okhttp3.Headers; import okhttp3.HttpUrl; public class OwnCloudClient extends HttpClient { - public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String NEW_WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/"; public static final String NEW_WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/"; public static final String STATUS_PATH = "/status.php"; @@ -63,8 +63,6 @@ public class OwnCloudClient extends HttpClient { private static final String TAG = OwnCloudClient.class.getSimpleName(); private static final int MAX_REDIRECTIONS_COUNT = 3; private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1; - private static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header"; - private static final boolean PARAM_SINGLE_COOKIE_HEADER_VALUE = true; private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version"; private static byte[] sExhaustBuffer = new byte[1024]; @@ -101,15 +99,6 @@ public class OwnCloudClient extends HttpClient { mInstanceNumber = sIntanceCounter++; Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient"); - //TODO -// getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); -// getParams().setParameter( -// PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers -// PARAM_SINGLE_COOKIE_HEADER_VALUE -// ); - -// applyProxySettings(); - clearCredentials(); } @@ -198,7 +187,7 @@ public class OwnCloudClient extends HttpClient { // Release the connection to avoid reach the max number of connections per host // due to it will be set a different url - exhaustResponse(method.getResponseAsStream()); + exhaustResponse(method.getResponseBodyAsStream()); method.setUrl(HttpUrl.parse(location)); final String destination = method.getRequestHeader("Destination") != null @@ -206,7 +195,7 @@ public class OwnCloudClient extends HttpClient { : method.getRequestHeader("destination"); if (destination != null) { - final int suffixIndex = location.lastIndexOf(WEBDAV_PATH_4_0); + final int suffixIndex = location.lastIndexOf(getNewFilesWebDavUri().toString()); final String redirectionBase = location.substring(0, suffixIndex); final String destinationPath = destination.substring(mBaseUri.toString().length()); @@ -250,10 +239,6 @@ public class OwnCloudClient extends HttpClient { } } - public Uri getOldFilesWebdavUri() { - return Uri.parse(mBaseUri + WEBDAV_PATH_4_0); - } - public Uri getNewFilesWebDavUri() { return mCredentials instanceof OwnCloudAnonymousCredentials ? Uri.parse(mBaseUri + NEW_WEBDAV_FILES_PATH_4_0) @@ -288,6 +273,15 @@ public class OwnCloudClient extends HttpClient { return mCredentials; } + private void logCookie(Cookie cookie) { + Log_OC.d(TAG, "Cookie name: " + cookie.name()); + Log_OC.d(TAG, " value: " + cookie.value()); + Log_OC.d(TAG, " domain: " + cookie.domain()); + Log_OC.d(TAG, " path: " + cookie.path()); + Log_OC.d(TAG, " expiryDate: " + cookie.expiresAt()); + Log_OC.d(TAG, " secure: " + cookie.secure()); + } + private void logCookiesAtRequest(Headers headers, String when) { int counter = 0; for (final String cookieHeader : headers.toMultimap().get("cookie")) { @@ -331,16 +325,6 @@ public class OwnCloudClient extends HttpClient { getAccount().getBaseUri().toString()), cookies); } - private void logCookie(Cookie cookie) { - Log_OC.d(TAG, "Cookie name: " + cookie.name()); - Log_OC.d(TAG, " value: " + cookie.value()); - Log_OC.d(TAG, " domain: " + cookie.domain()); - Log_OC.d(TAG, " path: " + cookie.path()); - Log_OC.d(TAG, " expiryDate: " + cookie.expiresAt()); - Log_OC.d(TAG, " secure: " + cookie.secure()); - } - - public void setOwnCloudVersion(OwnCloudVersion version) { mVersion = version; } diff --git a/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java index a77568f5..94a0c51d 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,9 +24,6 @@ package com.owncloud.android.lib.common; -import java.io.IOException; -import java.security.GeneralSecurityException; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountManagerFuture; @@ -40,12 +37,11 @@ import android.os.Bundle; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; -import com.owncloud.android.lib.common.http.HttpClient; -import com.owncloud.android.lib.common.network.NetworkUtils; import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; +import java.io.IOException; + public class OwnCloudClientFactory { final private static String TAG = OwnCloudClientFactory.class.getSimpleName(); @@ -123,9 +119,6 @@ public class OwnCloudClientFactory { } else { - //String password = am.getPassword(account); - //String password = am.blockingGetAuthToken(account, MainApp.getAuthTokenTypePass(), - // false); AccountManagerFuture future = am.getAuthToken( account, AccountTypeUtils.getAuthTokenTypePass(account.type), diff --git a/src/com/owncloud/android/lib/common/OwnCloudClientManager.java b/src/com/owncloud/android/lib/common/OwnCloudClientManager.java index e7fe77af..5ef81382 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClientManager.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClientManager.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,6 +38,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce * * @author David A. Velasco * @author masensio + * @author Christian Schabesberger */ public interface OwnCloudClientManager { @@ -51,5 +52,4 @@ public interface OwnCloudClientManager { void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/SingleSessionManager.java b/src/com/owncloud/android/lib/common/SingleSessionManager.java index e36f5fe2..f041f465 100644 --- a/src/com/owncloud/android/lib/common/SingleSessionManager.java +++ b/src/com/owncloud/android/lib/common/SingleSessionManager.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -50,6 +50,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; * * @author David A. Velasco * @author masensio + * @author Christian Schabesberger */ public class SingleSessionManager implements OwnCloudClientManager { diff --git a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java index a1499481..bf3f92ab 100644 --- a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2017 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * Copyright (C) 2012 Bartek Przybylski * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,10 +25,6 @@ package com.owncloud.android.lib.common.accounts; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountsException; @@ -43,6 +39,10 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + import okhttp3.Cookie; public class AccountUtils { @@ -59,11 +59,23 @@ public class AccountUtils { */ public static String getWebDavUrlForAccount(Context context, Account account) throws AccountNotFoundException { + String webDavUrlForAccount = ""; - return getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_PATH_4_0; + try { + OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account); + webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.NEW_WEBDAV_FILES_PATH_4_0 + + ownCloudCredentials.getUsername(); + } catch (OperationCanceledException e) { + e.printStackTrace(); + } catch (AuthenticatorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return webDavUrlForAccount; } - /** * Extracts url server from the account * @@ -84,7 +96,6 @@ public class AccountUtils { return baseurl; } - /** * Get the username corresponding to an OC account. * @@ -130,7 +141,7 @@ public class AccountUtils { public static OwnCloudCredentials getCredentialsForAccount(Context context, Account account) throws OperationCanceledException, AuthenticatorException, IOException { - OwnCloudCredentials credentials = null; + OwnCloudCredentials credentials; AccountManager am = AccountManager.get(context); String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2); @@ -174,10 +185,8 @@ public class AccountUtils { } return credentials; - } - public static String buildAccountNameOld(Uri serverBaseUrl, String username) { if (serverBaseUrl.getScheme() == null) { serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString()); @@ -216,7 +225,6 @@ public class AccountUtils { // Log_OC.d(TAG, "Saving Cookies: "+ cookiesString ); } } - } /** @@ -236,7 +244,7 @@ public class AccountUtils { // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); - Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getOldFilesWebdavUri(); + Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getNewFilesWebDavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { @@ -275,7 +283,6 @@ public class AccountUtils { } } - public static class Constants { /** * Version should be 3 numbers separated by dot so it can be parsed by @@ -316,5 +323,4 @@ public class AccountUtils { public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token"; } - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java b/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java index f83e6fd5..6d82bdb3 100644 --- a/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java +++ b/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,10 +24,9 @@ package com.owncloud.android.lib.common.authentication.oauth; - /** - * * @author David A. Velasco + * @author Christian Schabesberger */ public class BearerCredentials { @@ -96,6 +95,4 @@ public class BearerCredentials { } return false; } - -} - +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java index a3cea994..a3e5666f 100644 --- a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java +++ b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java @@ -1,7 +1,8 @@ /* ownCloud Android Library is available under MIT license * * @author David A. Velasco - * Copyright (C) 2017 ownCloud GmbH. + * @author Christian Schabesberger + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -105,8 +106,6 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation(ResultCode.OK); - client.exhaustResponse(postMethod.getResponseAsStream()); + client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { @@ -144,5 +143,4 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation> run(OwnCloudClient client) { try { - final RequestBody requestBody = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart(OAuth2Constants.KEY_GRANT_TYPE, @@ -96,11 +96,8 @@ public class OAuth2RefreshAccessTokenOperation extends RemoteOperation(ResultCode.OAUTH2_ERROR) : result; - } else { return new RemoteOperationResult<>(postMethod); } @@ -135,5 +131,4 @@ public class OAuth2RefreshAccessTokenOperation extends RemoteOperation true); // TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok. //.hostnameVerifier(new BrowserCompatHostnameVerifier()); - if(BuildConfig.DEBUG) { - clientBuilder.addNetworkInterceptor(new StethoInterceptor()); - } sOkHttpClient = clientBuilder.build(); } catch (Exception e) { @@ -93,6 +87,7 @@ public class HttpClient { if (sOkHttpInterceptor == null) { sOkHttpInterceptor = new HttpInterceptor(); addHeaderForAllRequests(HttpConstants.USER_AGENT_HEADER, OwnCloudClientManagerFactory.getUserAgent()); + addHeaderForAllRequests(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true"); } return sOkHttpInterceptor; } diff --git a/src/com/owncloud/android/lib/common/http/HttpConstants.java b/src/com/owncloud/android/lib/common/http/HttpConstants.java index 80558a54..f1de6ddc 100644 --- a/src/com/owncloud/android/lib/common/http/HttpConstants.java +++ b/src/com/owncloud/android/lib/common/http/HttpConstants.java @@ -42,6 +42,7 @@ public class HttpConstants { public static final String CONTENT_TYPE_HEADER = "Content-Type"; public static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; public static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; + public static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header"; /*********************************************************************************************************** ************************************************ STATUS CODES ********************************************* diff --git a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java index aaadcebf..39c3d14e 100644 --- a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java @@ -74,7 +74,6 @@ public abstract class HttpBaseMethod { return mCall.isCanceled(); } - ////////////////////////////// // For override ////////////////////////////// @@ -98,7 +97,7 @@ public abstract class HttpBaseMethod { return mResponse.body().string(); } - public InputStream getResponseAsStream() { + public InputStream getResponseBodyAsStream() { return mResponse.body().byteStream(); } diff --git a/src/com/owncloud/android/lib/common/network/ChunkFromFileChannelRequestEntity.java b/src/com/owncloud/android/lib/common/network/ChunkFromFileChannelRequestEntity.java deleted file mode 100644 index e5017112..00000000 --- a/src/com/owncloud/android/lib/common/network/ChunkFromFileChannelRequestEntity.java +++ /dev/null @@ -1,165 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. - * - * 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.lib.common.network; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - - - -import com.owncloud.android.lib.common.utils.Log_OC; - - -/** - * A RequestEntity that represents a PIECE of a file. - * - * @author David A. Velasco - */ -public class ChunkFromFileChannelRequestEntity implements ProgressiveDataTransferer { - - private static final String TAG = ChunkFromFileChannelRequestEntity.class.getSimpleName(); - - //private final File mFile; - private final FileChannel mChannel; - private final String mContentType; - private final long mChunkSize; - private final File mFile; - private long mOffset; - private long mTransferred; - Set mDataTransferListeners = new HashSet<>(); - private ByteBuffer mBuffer = ByteBuffer.allocate(4096); - - public ChunkFromFileChannelRequestEntity( - final FileChannel channel, final String contentType, long chunkSize, final File file - ) { - super(); - if (channel == null) { - throw new IllegalArgumentException("File may not be null"); - } - if (chunkSize <= 0) { - throw new IllegalArgumentException("Chunk size must be greater than zero"); - } - mChannel = channel; - mContentType = contentType; - mChunkSize = chunkSize; - mFile = file; - mOffset = 0; - mTransferred = 0; - } - - public void setOffset(long offset) { - mOffset = offset; - } - - public long getContentLength() { - try { - return Math.min(mChunkSize, mChannel.size() - mChannel.position()); - } catch (IOException e) { - return mChunkSize; - } - } - - public String getContentType() { - return mContentType; - } - - public boolean isRepeatable() { - return true; - } - - @Override - public void addDatatransferProgressListener(OnDatatransferProgressListener listener) { - synchronized (mDataTransferListeners) { - mDataTransferListeners.add(listener); - } - } - - @Override - public void addDatatransferProgressListeners(Collection listeners) { - synchronized (mDataTransferListeners) { - mDataTransferListeners.addAll(listeners); - } - } - - @Override - public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { - synchronized (mDataTransferListeners) { - mDataTransferListeners.remove(listener); - } - } - - - public void writeRequest(final OutputStream out) throws IOException { - int readCount; - Iterator it; - - try { - mChannel.position(mOffset); - long size = mFile.length(); - if (size == 0) size = -1; - long maxCount = Math.min(mOffset + mChunkSize, mChannel.size()); - while (mChannel.position() < maxCount) { - readCount = mChannel.read(mBuffer); - try { - out.write(mBuffer.array(), 0, readCount); - } catch (IOException io) { - // work-around try catch to filter exception in writing - throw new FileRequestEntity.WriteException(io); - } - mBuffer.clear(); - if (mTransferred < maxCount) { // condition to avoid accumulate progress for repeated chunks - mTransferred += readCount; - } - synchronized (mDataTransferListeners) { - it = mDataTransferListeners.iterator(); - while (it.hasNext()) { - it.next().onTransferProgress(readCount, mTransferred, size, mFile.getAbsolutePath()); - } - } - } - - } catch (IOException io) { - // any read problem will be handled as if the file is not there - if (io instanceof FileNotFoundException) { - throw io; - } else { - FileNotFoundException fnf = new FileNotFoundException("Exception reading source file"); - fnf.initCause(io); - throw fnf; - } - - } catch (FileRequestEntity.WriteException we) { - throw we.getWrapped(); - } - } -} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/network/FileRequestEntity.java b/src/com/owncloud/android/lib/common/network/FileRequestEntity.java deleted file mode 100644 index 2bc0ee27..00000000 --- a/src/com/owncloud/android/lib/common/network/FileRequestEntity.java +++ /dev/null @@ -1,93 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. - * Copyright (C) 2012 Bartek Przybylski - * - * 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.lib.common.network; - - - -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - - - -/** - * A RequestEntity that represents a File. - * - */ -public class FileRequestEntity implements ProgressiveDataTransferer { - - final File mFile; - final String mContentType; - Set mDataTransferListeners = new HashSet<>(); - - public FileRequestEntity(final File file, final String contentType) { - super(); - this.mFile = file; - this.mContentType = contentType; - if (file == null) { - throw new IllegalArgumentException("File may not be null"); - } - } - - public String getContentType() { - return mContentType; - } - - @Override - public void addDatatransferProgressListener(OnDatatransferProgressListener listener) { - synchronized (mDataTransferListeners) { - mDataTransferListeners.add(listener); - } - } - - @Override - public void addDatatransferProgressListeners(Collection listeners) { - synchronized (mDataTransferListeners) { - mDataTransferListeners.addAll(listeners); - } - } - - @Override - public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { - synchronized (mDataTransferListeners) { - mDataTransferListeners.remove(listener); - } - } - - protected static class WriteException extends Exception { - IOException mWrapped; - - WriteException(IOException wrapped) { - mWrapped = wrapped; - } - - public IOException getWrapped() { - return mWrapped; - } - } -} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java index 19c7517a..df6c4f1e 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -81,10 +81,10 @@ public abstract class RemoteOperation implements Runnable { if (account == null) throw new IllegalArgumentException - ("Trying to onExecute a remote operation with a NULL Account"); + ("Trying to execute a remote operation with a NULL Account"); if (context == null) throw new IllegalArgumentException - ("Trying to onExecute a remote operation with a NULL Context"); + ("Trying to execute a remote operation with a NULL Context"); // mAccount and mContext in the runnerThread to create below mAccount = account; mContext = context.getApplicationContext(); @@ -114,7 +114,7 @@ public abstract class RemoteOperation implements Runnable { OnRemoteOperationListener listener, Handler listenerHandler) { if (client == null) { throw new IllegalArgumentException - ("Trying to onExecute a remote operation with a NULL OwnCloudClient"); + ("Trying to execute a remote operation with a NULL OwnCloudClient"); } mClient = client; if (client.getAccount() != null) { @@ -124,7 +124,7 @@ public abstract class RemoteOperation implements Runnable { if (listener == null) { throw new IllegalArgumentException - ("Trying to onExecute a remote operation asynchronously " + + ("Trying to execute a remote operation asynchronously " + "without a listener to notiy the result"); } mListener = listener; @@ -182,10 +182,10 @@ public abstract class RemoteOperation implements Runnable { */ public RemoteOperationResult execute(Account account, Context context) { if (account == null) - throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "Account"); if (context == null) - throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "Context"); mAccount = account; mContext = context.getApplicationContext(); @@ -205,7 +205,7 @@ public abstract class RemoteOperation implements Runnable { */ public RemoteOperationResult execute(OwnCloudClient client) { if (client == null) - throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "OwnCloudClient"); mClient = client; if (client.getAccount() != null) { @@ -227,7 +227,7 @@ public abstract class RemoteOperation implements Runnable { */ public RemoteOperationResult execute(OkHttpClient client, Context context) { if (client == null) - throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "OwnCloudClient"); mHttpClient = client; mContext = context; @@ -283,5 +283,4 @@ public abstract class RemoteOperation implements Runnable { mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); } } - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index eabcc34c..03e5028d 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -1,3 +1,27 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2018 ownCloud GmbH. + * + * 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.lib.common.operations; import android.accounts.Account; diff --git a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java index eb875051..f01c0644 100644 --- a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit; * Allows renaming the moving file/folder at the same time. * * @author David A. Velasco + * @author Christian Schabesberger */ public class CopyRemoteFileOperation extends RemoteOperation { @@ -116,7 +117,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { } else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) { result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); - client.exhaustResponse(copyMethod.getResponseAsStream()); + client.exhaustResponse(copyMethod.getResponseBodyAsStream()); /// for other errors that could be explicitly handled, check first: @@ -124,7 +125,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { } else { result = new RemoteOperationResult<>(copyMethod); - client.exhaustResponse(copyMethod.getResponseAsStream()); + client.exhaustResponse(copyMethod.getResponseBodyAsStream()); } Log.i(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + diff --git a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java index 7d4095bc..31a6555d 100644 --- a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java @@ -90,7 +90,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation { result = createFolder(client); // second (and last) try } } - } else { result = new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); } @@ -98,7 +97,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation { return result; } - private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result; try { @@ -112,7 +110,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation { ? new RemoteOperationResult<>(ResultCode.OK) : new RemoteOperationResult<>(mkcol); Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); - client.exhaustResponse(mkcol.getResponseAsStream()); + client.exhaustResponse(mkcol.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult<>(e); diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 4902b584..46d6ec52 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -110,7 +110,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { status = client.executeHttpMethod(mGet); if (isSuccess(status)) { targetFile.createNewFile(); - bis = new BufferedInputStream(mGet.getResponseAsStream()); + bis = new BufferedInputStream(mGet.getResponseBodyAsStream()); fos = new FileOutputStream(targetFile); long transferred = 0; @@ -160,12 +160,12 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } } else { - client.exhaustResponse(mGet.getResponseAsStream()); + client.exhaustResponse(mGet.getResponseBodyAsStream()); // TODO some kind of error control! } } else if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR) { - client.exhaustResponse(mGet.getResponseAsStream()); + client.exhaustResponse(mGet.getResponseBodyAsStream()); } // else, body read by RemoteOperationResult constructor diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 4c6ad18f..67d7c61e 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -43,7 +43,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R * Operation to check the existence or absence of a path in a remote server. * * @author David A. Velasco - * @author David GonzálezVerdugo + * @author David González Verdugo */ public class ExistenceCheckRemoteOperation extends RemoteOperation { diff --git a/src/com/owncloud/android/lib/resources/files/FileUtils.java b/src/com/owncloud/android/lib/resources/files/FileUtils.java index 71277b44..a07ef14c 100644 --- a/src/com/owncloud/android/lib/resources/files/FileUtils.java +++ b/src/com/owncloud/android/lib/resources/files/FileUtils.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,10 +24,9 @@ package com.owncloud.android.lib.resources.files; -import java.io.File; - import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; + +import java.io.File; public class FileUtils { diff --git a/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java index df115b78..9673ee95 100644 --- a/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java @@ -126,7 +126,6 @@ public class MoveRemoteFileOperation extends RemoteOperation { move.setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS); move.setConnectionTimeout(MOVE_CONNECTION_TIMEOUT, TimeUnit.SECONDS); - //int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); final int status = client.executeHttpMethod(move); /// process response if(isSuccess(status)) { @@ -134,14 +133,14 @@ public class MoveRemoteFileOperation extends RemoteOperation { } else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) { result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); - client.exhaustResponse(move.getResponseAsStream()); + client.exhaustResponse(move.getResponseBodyAsStream()); /// for other errors that could be explicitly handled, check first: /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 } else { result = new RemoteOperationResult<>(move); - client.exhaustResponse(move.getResponseAsStream()); + client.exhaustResponse(move.getResponseBodyAsStream()); } Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index 7985d658..9fcf0d65 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -35,8 +35,6 @@ import com.owncloud.android.lib.common.utils.Log_OC; import java.net.URL; import java.util.concurrent.TimeUnit; -import at.bitfire.dav4android.DavResource; - import static com.owncloud.android.lib.common.http.methods.webdav.DavConstants.DEPTH_0; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; @@ -96,7 +94,7 @@ public class ReadRemoteFileOperation extends RemoteOperation { } else { result = new RemoteOperationResult<>(propfind); - client.exhaustResponse(propfind.getResponseAsStream()); + client.exhaustResponse(propfind.getResponseBodyAsStream()); } } catch (Exception e) { diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index 9265abe5..dd823218 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -37,7 +37,6 @@ import com.owncloud.android.lib.common.utils.Log_OC; import java.net.URL; import java.util.ArrayList; -import at.bitfire.dav4android.DavResource; import at.bitfire.dav4android.Response; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; diff --git a/src/com/owncloud/android/lib/resources/files/RemoteFile.java b/src/com/owncloud/android/lib/resources/files/RemoteFile.java index 36ca6baf..d28462ec 100644 --- a/src/com/owncloud/android/lib/resources/files/RemoteFile.java +++ b/src/com/owncloud/android/lib/resources/files/RemoteFile.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,6 +53,7 @@ import static com.owncloud.android.lib.common.OwnCloudClient.NEW_WEBDAV_FILES_PA * Contains the data of a Remote File from a WebDavEntry * * @author masensio + * @author Christian Schabesberger */ public class RemoteFile implements Parcelable, Serializable { diff --git a/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index d5ab14e1..ef19413d 100644 --- a/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java @@ -57,7 +57,6 @@ public class RenameRemoteFileOperation extends RemoteOperation { private String mNewName; private String mNewRemotePath; - /** * Constructor * @@ -121,7 +120,7 @@ public class RenameRemoteFileOperation extends RemoteOperation { Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + result.getLogMessage() ); - client.exhaustResponse(move.getResponseAsStream()); + client.exhaustResponse(move.getResponseBodyAsStream()); return result; } catch (Exception e) { final RemoteOperationResult result = new RemoteOperationResult<>(e); @@ -143,5 +142,4 @@ public class RenameRemoteFileOperation extends RemoteOperation { RemoteOperationResult exists = existenceCheckRemoteOperation.run(client); return exists.isSuccess(); } - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 4027fa04..d0e4b807 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -136,7 +136,6 @@ public class UploadRemoteFileOperation extends RemoteOperation { } mPutMethod.addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, String.valueOf(fileToUpload.length())); - mPutMethod.addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, mFileLastModifTimestamp); mPutMethod.setRequestBody(mFileRequestBody); diff --git a/src/com/owncloud/android/lib/resources/files/chunks/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/chunks/ChunkedUploadRemoteFileOperation.java index f50025f1..91e6734e 100644 --- a/src/com/owncloud/android/lib/resources/files/chunks/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/chunks/ChunkedUploadRemoteFileOperation.java @@ -43,7 +43,6 @@ import okhttp3.MediaType; import static com.owncloud.android.lib.common.http.HttpConstants.IF_MATCH_HEADER; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; -import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; /** * Remote operation performing the chunked upload of a remote file to the ownCloud server. diff --git a/src/com/owncloud/android/lib/resources/files/chunks/RemoveRemoteChunksFolderOperation.java b/src/com/owncloud/android/lib/resources/files/chunks/RemoveRemoteChunksFolderOperation.java index 831cc79c..48602313 100644 --- a/src/com/owncloud/android/lib/resources/files/chunks/RemoveRemoteChunksFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/chunks/RemoveRemoteChunksFolderOperation.java @@ -1,3 +1,28 @@ +/* ownCloud Android Library is available under MIT license + * @author David González Verdugo + * Copyright (C) 2018 ownCloud GmbH. + * + * 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.lib.resources.files.chunks; import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation; diff --git a/src/com/owncloud/android/lib/resources/shares/ShareParserResult.java b/src/com/owncloud/android/lib/resources/shares/ShareParserResult.java index 75dea43c..7ba076e6 100644 --- a/src/com/owncloud/android/lib/resources/shares/ShareParserResult.java +++ b/src/com/owncloud/android/lib/resources/shares/ShareParserResult.java @@ -1,3 +1,28 @@ +/* ownCloud Android Library is available under MIT license + * @author Christian Schabesberger + * Copyright (C) 2018 ownCloud GmbH. + * + * 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.lib.resources.shares; import java.util.ArrayList; diff --git a/src/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.java b/src/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.java index 9f9d84b1..2d6388ed 100644 --- a/src/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.java +++ b/src/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.java @@ -1,6 +1,7 @@ /* ownCloud Android Library is available under MIT license * @author David A. Velasco * @author David González Verdugo + * @author Christian Schabesberger * Copyright (C) 2018 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -138,5 +139,4 @@ public class ShareToRemoteOperationResultParser { return result; } - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java index 8caf2a4a..68728c3e 100644 --- a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java +++ b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java @@ -31,7 +31,6 @@ import android.net.Uri; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; -import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; @@ -41,10 +40,7 @@ import org.json.JSONObject; import java.net.URL; import java.util.concurrent.TimeUnit; - import javax.net.ssl.SSLException; -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.SSLPeerUnverifiedException; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java index fd4d343f..9cefac22 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; - import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -42,7 +41,6 @@ import java.net.URL; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; - /** * Gets avatar about the user logged in, if available * @author David A. Velasco @@ -113,7 +111,7 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation(getMethod); - client.exhaustResponse(getMethod.getResponseAsStream()); + client.exhaustResponse(getMethod.getResponseBodyAsStream()); } } catch (Exception e) { diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java index b9b28e16..7e3c61f2 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java @@ -35,11 +35,8 @@ import org.json.JSONObject; import java.net.URL; -import okhttp3.Request; - import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; - /** * Gets information (id, display name, and e-mail address) about the user logged in. * @@ -71,11 +68,6 @@ public class GetRemoteUserInfoOperation extends RemoteOperation