@@ -74,6 +74,11 @@ public class FixedChunkUploadRemoteOperation extends RemoteOperation implements
74
74
// Fixed 1 MB chunk size (1024 * 1024 bytes)
75
75
public static final long FIXED_CHUNK_SIZE = 1024 * 1024 ;
76
76
77
+ // Constants for repeated string literals
78
+ private static final String BYTES_SUFFIX = " bytes" ;
79
+ private static final String SIZE_SEPARATOR = ", size: " ;
80
+ private static final String DAV_UPLOADS_PATH = "/remote.php/dav/uploads/" ;
81
+
77
82
private final String mLocalPath ;
78
83
private final String mRemotePath ;
79
84
private final String mMimeType ;
@@ -165,8 +170,8 @@ protected RemoteOperationResult run(OwnCloudClient client) {
165
170
mFileSize = localFile .length ();
166
171
167
172
Log_OC .d (TAG , "FixedChunkUploadRemoteOperation: Processing file " + localFile .getName () +
168
- " with size " + mFileSize + " bytes" );
169
- Log_OC .d (TAG , "FixedChunkUploadRemoteOperation: FIXED_CHUNK_SIZE = " + FIXED_CHUNK_SIZE + " bytes" );
173
+ " with size " + mFileSize + BYTES_SUFFIX );
174
+ Log_OC .d (TAG , "FixedChunkUploadRemoteOperation: FIXED_CHUNK_SIZE = " + FIXED_CHUNK_SIZE + BYTES_SUFFIX );
170
175
171
176
// This operation is only used for large files (>2MB) to provide multipart upload
172
177
Log_OC .d (TAG , "FixedChunkUploadRemoteOperation: Using chunked upload for large file" );
@@ -190,7 +195,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
190
195
*/
191
196
private RemoteOperationResult uploadFileDirectly (OwnCloudClient client , File localFile ) {
192
197
Log_OC .d (TAG , "FixedChunkUploadRemoteOperation.uploadFileDirectly() - ENTRY" );
193
- Log_OC .d (TAG , "uploadFileDirectly: File size = " + localFile .length () + " bytes" );
198
+ Log_OC .d (TAG , "uploadFileDirectly: File size = " + localFile .length () + BYTES_SUFFIX );
194
199
195
200
try {
196
201
// Use the existing UploadFileRemoteOperation for small files
@@ -236,7 +241,7 @@ private RemoteOperationResult uploadFileInChunks(OwnCloudClient client, File loc
236
241
237
242
try {
238
243
Log_OC .d (TAG , "uploadFileInChunks: Starting Nextcloud v2 chunked upload for file: " + localFile .getName () +
239
- ", size: " + mFileSize + " bytes , using " + FIXED_CHUNK_SIZE + " byte chunks" );
244
+ SIZE_SEPARATOR + mFileSize + BYTES_SUFFIX + ", using " + FIXED_CHUNK_SIZE + " byte chunks" );
240
245
241
246
mTotalChunks = (mFileSize + FIXED_CHUNK_SIZE - 1 ) / FIXED_CHUNK_SIZE ; // Ceiling division
242
247
mCurrentChunk = 0 ;
@@ -284,7 +289,7 @@ private RemoteOperationResult uploadFileInChunks(OwnCloudClient client, File loc
284
289
long chunkSize = chunkEnd - chunkStart ;
285
290
286
291
Log_OC .d (TAG , "uploadFileInChunks: Uploading chunk " + mCurrentChunk + "/" + mTotalChunks +
287
- " (bytes " + chunkStart + "-" + (chunkEnd - 1 ) + ", size: " + chunkSize + ")" );
292
+ " (bytes " + chunkStart + "-" + (chunkEnd - 1 ) + SIZE_SEPARATOR + chunkSize + ")" );
288
293
289
294
290
295
// Read chunk data
@@ -358,7 +363,7 @@ private RemoteOperationResult createUploadSession(OwnCloudClient client) {
358
363
try {
359
364
String encodedUsername = URLEncoder .encode (client .getCredentials ().getUsername (), StandardCharsets .UTF_8 .toString ());
360
365
String encodedSessionId = URLEncoder .encode (mUploadSessionId , StandardCharsets .UTF_8 .toString ());
361
- sessionUrl = client .getBaseUri () + "/remote.php/dav/uploads/" + encodedUsername + "/" + encodedSessionId ;
366
+ sessionUrl = client .getBaseUri () + DAV_UPLOADS_PATH + encodedUsername + "/" + encodedSessionId ;
362
367
} catch (Exception e ) {
363
368
Log_OC .e (TAG , "createUploadSession: Error encoding URL components" , e );
364
369
return new RemoteOperationResult (e );
@@ -417,15 +422,15 @@ private RemoteOperationResult uploadChunkToSession(OwnCloudClient client, byte[]
417
422
}
418
423
419
424
try {
420
- Log_OC .d (TAG , "uploadChunkToSession: Uploading chunk " + chunkNumber + " with " + chunkData .length + " bytes" );
425
+ Log_OC .d (TAG , "uploadChunkToSession: Uploading chunk " + chunkNumber + " with " + chunkData .length + BYTES_SUFFIX );
421
426
422
427
// Construct chunk URL - chunks are named as numbers (1, 2, 3...)
423
428
String chunkUrl ;
424
429
try {
425
430
String encodedUsername = URLEncoder .encode (client .getCredentials ().getUsername (), StandardCharsets .UTF_8 .toString ());
426
431
String encodedSessionId = URLEncoder .encode (mUploadSessionId , StandardCharsets .UTF_8 .toString ());
427
432
String chunkFileName = String .format ("%05d" , chunkNumber ); // 5-digit padded number
428
- chunkUrl = client .getBaseUri () + "/remote.php/dav/uploads/" + encodedUsername + "/" + encodedSessionId + "/" + chunkFileName ;
433
+ chunkUrl = client .getBaseUri () + DAV_UPLOADS_PATH + encodedUsername + "/" + encodedSessionId + "/" + chunkFileName ;
429
434
} catch (Exception e ) {
430
435
Log_OC .e (TAG , "uploadChunkToSession: Error encoding URL components" , e );
431
436
return new RemoteOperationResult (e );
@@ -512,7 +517,7 @@ private RemoteOperationResult assembleChunks(OwnCloudClient client) {
512
517
try {
513
518
String encodedUsername = URLEncoder .encode (client .getCredentials ().getUsername (), StandardCharsets .UTF_8 .toString ());
514
519
String encodedSessionId = URLEncoder .encode (mUploadSessionId , StandardCharsets .UTF_8 .toString ());
515
- assemblySourceUrl = client .getBaseUri () + "/remote.php/dav/uploads/" + encodedUsername + "/" + encodedSessionId + "/.file" ;
520
+ assemblySourceUrl = client .getBaseUri () + DAV_UPLOADS_PATH + encodedUsername + "/" + encodedSessionId + "/.file" ;
516
521
} catch (Exception e ) {
517
522
Log_OC .e (TAG , "assembleChunks: Error encoding source URL" , e );
518
523
return new RemoteOperationResult (e );
@@ -658,7 +663,7 @@ private int checkExistingSession(OwnCloudClient client) {
658
663
try {
659
664
String encodedUsername = URLEncoder .encode (client .getCredentials ().getUsername (), StandardCharsets .UTF_8 .toString ());
660
665
String encodedSessionId = URLEncoder .encode (mUploadSessionId , StandardCharsets .UTF_8 .toString ());
661
- String sessionUrl = client .getBaseUri () + "/remote.php/dav/uploads/" + encodedUsername + "/" + encodedSessionId ;
666
+ String sessionUrl = client .getBaseUri () + DAV_UPLOADS_PATH + encodedUsername + "/" + encodedSessionId ;
662
667
663
668
Log_OC .d (TAG , "checkExistingSession: Checking for existing session: " + sessionUrl );
664
669
@@ -747,7 +752,7 @@ private void updateProgress(long bytesUploaded, String fileName) {
747
752
// Calculate percentage - same logic as FileUploadWorker's getPercent()
748
753
int currentPercent = (int ) ((100.0 * bytesUploaded ) / mFileSize );
749
754
750
- Log_OC .d (TAG , "updateProgress: " + bytesUploaded + "/" + mFileSize + " bytes (" + currentPercent + "%)" );
755
+ Log_OC .d (TAG , "updateProgress: " + bytesUploaded + "/" + mFileSize + BYTES_SUFFIX + " (" + currentPercent + "%)" );
751
756
752
757
// Report progress to all listeners (including FileUploadWorker)
753
758
for (OnDatatransferProgressListener listener : mDataTransferListeners ) {
0 commit comments