Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 070ac89

Browse files
committed
Use Android separator instead of homemade one
1 parent d289277 commit 070ac89

File tree

9 files changed

+22
-29
lines changed

9 files changed

+22
-29
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import okhttp3.Cookie;
4242
import timber.log.Timber;
4343

44+
import java.io.File;
4445
import java.io.IOException;
4546
import java.util.ArrayList;
4647
import java.util.List;
@@ -249,7 +250,7 @@ public static void restoreCookies(Account account, OwnCloudClient client, Contex
249250
.domain(serverUri.getHost())
250251
.path(
251252
serverUri.getPath().equals("")
252-
? FileUtils.PATH_SEPARATOR
253+
? File.separator
253254
: serverUri.getPath()
254255
)
255256
.build());

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,24 @@
2929
import java.io.File;
3030

3131
public class FileUtils {
32-
public static final String PATH_SEPARATOR = "/";
3332
public static final String FINAL_CHUNKS_FILE = ".file";
3433

3534
static String getParentPath(String remotePath) {
3635
String parentPath = new File(remotePath).getParent();
37-
parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
36+
parentPath = parentPath.endsWith(File.separator) ? parentPath : parentPath + File.separator;
3837
return parentPath;
3938
}
4039

4140
/**
4241
* Validate the fileName to detect if contains any forbidden character: / , \ , < , > ,
4342
* : , " , | , ? , *
4443
*
45-
* @param fileName
46-
* @return
4744
*/
4845
public static boolean isValidName(String fileName) {
4946
boolean result = true;
5047

5148
Timber.d("fileName =======%s", fileName);
52-
if (fileName.contains(PATH_SEPARATOR)) {
49+
if (fileName.contains(File.separator)) {
5350
result = false;
5451
}
5552
return result;

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import at.bitfire.dav4android.property.owncloud.OCPrivatelink;
4242
import at.bitfire.dav4android.property.owncloud.OCSize;
4343

44+
import java.io.File;
4445
import java.io.Serializable;
4546
import java.math.BigDecimal;
4647
import java.util.List;
@@ -92,13 +93,13 @@ public RemoteFile() {
9293
/**
9394
* Create new {@link RemoteFile} with given path.
9495
* <p>
95-
* The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
96+
* The path received must be URL-decoded. Path separator must be File.separator, and it must be the first character in 'path'.
9697
*
9798
* @param path The remote path of the file.
9899
*/
99100
public RemoteFile(String path) {
100101
resetData();
101-
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
102+
if (path == null || path.length() <= 0 || !path.startsWith(File.separator)) {
102103
throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
103104
}
104105
mRemotePath = path;

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ public RenameRemoteFileOperation(String oldName, String oldRemotePath, String ne
6868
mNewName = newName;
6969

7070
String parent = (new File(mOldRemotePath)).getParent();
71-
parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent +
72-
FileUtils.PATH_SEPARATOR;
71+
parent = (parent.endsWith(File.separator)) ? parent : parent + File.separator;
7372
mNewRemotePath = parent + mNewName;
7473
if (isFolder) {
75-
mNewRemotePath += FileUtils.PATH_SEPARATOR;
74+
mNewRemotePath += File.separator;
7675
}
7776
}
7877

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/chunks/ChunkedUploadRemoteFileOperation.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,12 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws Excepti
8282
}
8383

8484
long offset = 0;
85-
String uriPrefix = client.getUploadsWebDavUri() + FileUtils.PATH_SEPARATOR + String.valueOf(mTransferId);
85+
String uriPrefix = client.getUploadsWebDavUri() + File.separator + mTransferId;
8686
long totalLength = fileToUpload.length();
8787
long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE);
8888

8989
for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
90-
mPutMethod = new PutMethod(
91-
new URL(uriPrefix + FileUtils.PATH_SEPARATOR + chunkIndex)
92-
);
90+
mPutMethod = new PutMethod(new URL(uriPrefix + File.separator + chunkIndex));
9391

9492
if (mRequiredEtag != null && mRequiredEtag.length() > 0) {
9593
mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\"");

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.owncloud.android.lib.resources.shares
2626

2727
import com.owncloud.android.lib.resources.files.FileUtils
28+
import java.io.File
2829

2930
/**
3031
* Contains the data of a Share from the Share API
@@ -48,7 +49,7 @@ data class RemoteShare(
4849
var permissions: Int = DEFAULT_PERMISSION,
4950
var sharedDate: Long = INIT_SHARED_DATE,
5051
var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS,
51-
var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR),
52+
var isFolder: Boolean = path.endsWith(File.separator),
5253
var userId: Long = 0,
5354
val isValid: Boolean = id > -1
5455
) {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@
2525
package com.owncloud.android.lib.resources.shares
2626

2727
import android.util.Xml
28-
2928
import com.owncloud.android.lib.common.network.WebdavUtils
30-
import com.owncloud.android.lib.resources.files.FileUtils
31-
3229
import org.xmlpull.v1.XmlPullParser
3330
import org.xmlpull.v1.XmlPullParserException
3431
import org.xmlpull.v1.XmlPullParserFactory
35-
32+
import java.io.File
3633
import java.io.IOException
3734
import java.io.InputStream
3835
import java.util.ArrayList
@@ -330,9 +327,9 @@ class ShareXMLParser {
330327

331328
private fun fixPathForFolder(share: RemoteShare) {
332329
if (share.isFolder && share.path.isNotEmpty() &&
333-
!share.path.endsWith(FileUtils.PATH_SEPARATOR)
330+
!share.path.endsWith(File.separator)
334331
) {
335-
share.path = share.path + FileUtils.PATH_SEPARATOR
332+
share.path = share.path + File.separator
336333
}
337334
}
338335

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
3030
import com.owncloud.android.lib.common.network.WebdavUtils
3131
import com.owncloud.android.lib.common.operations.RemoteOperation
3232
import com.owncloud.android.lib.common.operations.RemoteOperationResult
33-
import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR
3433
import timber.log.Timber
34+
import java.io.File
3535
import java.io.IOException
3636
import java.io.InputStream
3737
import java.net.URL
@@ -49,7 +49,7 @@ class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : RemoteOpe
4949

5050
try {
5151
val endPoint =
52-
client.baseUri.toString() + NON_OFFICIAL_AVATAR_PATH + client.credentials.username + PATH_SEPARATOR + avatarDimension
52+
client.baseUri.toString() + NON_OFFICIAL_AVATAR_PATH + client.credentials.username + File.separator + avatarDimension
5353
Timber.d("avatar URI: %s", endPoint)
5454

5555
val getMethod = GetMethod(URL(endPoint))

sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.owncloud.android.lib.common.operations.RemoteOperation;
4848
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
4949
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
50-
import com.owncloud.android.lib.resources.files.FileUtils;
5150
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
5251
import com.owncloud.android.lib.resources.files.RemoteFile;
5352
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
@@ -151,14 +150,14 @@ public void onClickHandler(View button) {
151150
}
152151

153152
private void startRefresh() {
154-
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
153+
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(File.separator);
155154
refreshOperation.execute(mClient, this, mHandler);
156155
}
157156

158157
private void startUpload() {
159158
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
160159
File fileToUpload = upFolder.listFiles()[0];
161-
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
160+
String remotePath = File.separator + fileToUpload.getName();
162161
String mimeType = getString(R.string.sample_file_mimetype);
163162

164163
// Get the last modification date of the file from the file system
@@ -174,7 +173,7 @@ private void startUpload() {
174173
private void startRemoteDeletion() {
175174
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
176175
File fileToUpload = upFolder.listFiles()[0];
177-
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
176+
String remotePath = File.separator + fileToUpload.getName();
178177

179178
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
180179
removeOperation.execute(mClient, this, mHandler);
@@ -185,7 +184,7 @@ private void startDownload() {
185184
downFolder.mkdir();
186185
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
187186
File fileToUpload = upFolder.listFiles()[0];
188-
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
187+
String remotePath = File.separator + fileToUpload.getName();
189188

190189
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath,
191190
downFolder.getAbsolutePath());

0 commit comments

Comments
 (0)