Skip to content

Commit 3a8b416

Browse files
small cleanup
1 parent 5d567a8 commit 3a8b416

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

DriveBackup/src/main/java/ratismal/drivebackup/uploaders/onedrive/OneDriveUploader.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
* Created by Redemption on 2/24/2016.
3434
*/
3535
public class OneDriveUploader extends Uploader {
36-
public static final int EXPONENTIAL_BACKOFF_MILLIS_DEFAULT = 1000;
37-
public static final int EXPONENTIAL_BACKOFF_FACTOR = 5;
38-
public static final int MAX_RETRY_ATTEMPTS = 3;
39-
40-
private final UploadLogger logger;
36+
private static final int EXPONENTIAL_BACKOFF_MILLIS_DEFAULT = 1000;
37+
private static final int EXPONENTIAL_BACKOFF_FACTOR = 5;
38+
private static final int MAX_RETRY_ATTEMPTS = 3;
4139

4240
private String accessToken = "";
4341
private String refreshToken;
@@ -48,6 +46,7 @@ public class OneDriveUploader extends Uploader {
4846
private static final MediaType jsonMediaType = MediaType.parse("application/json; charset=utf-8");
4947
private static final MediaType textMediaType = MediaType.parse("text/plain");
5048

49+
// as per ms docs should be multiple of 320 KiB (327'680 bytes)
5150
private static final int UPLOAD_CHUNK_SIZE = 5 * 1024 * 1024;
5251

5352
/**
@@ -212,7 +211,7 @@ private static String concatPath(@NotNull String lhs, @NotNull String rhs) {
212211
/**
213212
* creates all folders in the path if they don't already exist
214213
* @param path to create the folders for
215-
* @return FQID of the last folder in the path
214+
* @return {@link OneDriveUploader.FQID FQID} of the last folder in the path
216215
* @throws IOException if the request could not be executed
217216
* @throws GraphApiErrorException if the folder could not be found or created
218217
* @throws JSONException if the response does not contain the expected items
@@ -232,7 +231,7 @@ private FQID createPath(@NotNull String path) throws IOException, GraphApiErrorE
232231
* creates a folder at the root if it doesn't already exist
233232
* @param root of where to create the folder
234233
* @param folder name to create
235-
* @return FQID of the folder
234+
* @return {@link OneDriveUploader.FQID FQID} of the folder
236235
* @throws IOException if the request could not be executed
237236
* @throws GraphApiErrorException if the folder could not be found or created
238237
* @throws JSONException if the response does not contain the expected items
@@ -264,7 +263,7 @@ private FQID createFolder(@NotNull FQID root, @NotNull String folder) throws IOE
264263
/**
265264
* creates a folder at the drive root if it doesn't already exist
266265
* @param folder name to create
267-
* @return FQID of the folder
266+
* @return {@link OneDriveUploader.FQID FQID} of the folder
268267
* @throws IOException if the request could not be executed
269268
* @throws GraphApiErrorException if the root could not be found or created
270269
* @throws JSONException if the response does not contain the expected items
@@ -296,7 +295,7 @@ private FQID createRootFolder(@NotNull String folder) throws IOException, GraphA
296295
/**
297296
* tries to find folder in the drive root
298297
* @param folder to search
299-
* @return FQID or null if not found
298+
* @return {@link OneDriveUploader.FQID FQID} or null if not found
300299
* @throws IOException if the request could not be executed
301300
* @throws GraphApiErrorException if the root could not be retrieved
302301
* @throws JSONException if the response does not contain the expected items
@@ -330,7 +329,7 @@ private FQID getRootFolder(@NotNull String folder) throws IOException, GraphApiE
330329
* tries to find a folder under root
331330
* @param root to search
332331
* @param folder to look for
333-
* @return FQID or null if not found
332+
* @return {@link OneDriveUploader.FQID FQID} or null if not found
334333
* @throws IOException if the request could not be executed
335334
* @throws GraphApiErrorException if the children could not be retrieved
336335
* @throws JSONException if the response does not contain the expected items
@@ -389,7 +388,7 @@ private void recycleItem(@NotNull String driveId, @NotNull String itemId) throws
389388
* upload a file up to 250MB in size
390389
* @param file to upload
391390
* @param destinationFolder to upload the file into
392-
* @return FQID of the uploaded file
391+
* @return {@link OneDriveUploader.FQID FQID} of the uploaded file
393392
* @throws IOException if the request could not be executed
394393
* @throws GraphApiErrorException if the file could not be uploaded
395394
*/
@@ -414,8 +413,8 @@ private FQID uploadSmallFile(@NotNull File file, @NotNull FQID destinationFolder
414413
* creates an upload session for a file in a destination folder on OneDrive.
415414
*
416415
* @param fileName of the file to upload
417-
* @param destinationFolder as FQID
418-
* @return String with the upload URL for the file
416+
* @param destinationFolder as {@link OneDriveUploader.FQID FQID}
417+
* @return {@link String} with the upload URL for the file
419418
* @throws IOException if there is an error executing the request
420419
* @throws GraphApiErrorException if the upload session was not created
421420
* @throws JSONException if the response does not contain the expected values
@@ -470,7 +469,7 @@ private void uploadToSession(@NotNull String uploadURL, @NotNull RandomAccessFil
470469
retryCount = 0;
471470
} else if (uploadResponse.code() == 201 || uploadResponse.code() == 200) {
472471
break;
473-
} else { // TODO conflict after successful upload not handled
472+
} else { // TODO 404 409 416
474473
if (retryCount > MAX_RETRY_ATTEMPTS) {
475474
Request cancelRequest = new Request.Builder().url(uploadURL).delete().build();
476475
DriveBackup.httpClient.newCall(cancelRequest).execute().close();
@@ -535,7 +534,7 @@ private static class Range {
535534
private final int length;
536535

537536
/**
538-
* Creates an instance of the {@code Range} object
537+
* Creates an instance of the {@link OneDriveUploader.Range Range} object
539538
* @param start the index of the first byte
540539
* @param length of the range
541540
*/
@@ -545,7 +544,7 @@ public Range(long start, int length) {
545544
}
546545

547546
/**
548-
* Creates an instance of the {@code Range} object
547+
* Creates an instance of the {@link OneDriveUploader.Range Range} object
549548
* @param range in the format of {@code 000-000 or 000-}
550549
* @param maxLength to clamp the range to
551550
* @throws NumberFormatException if parseLong fails on range

0 commit comments

Comments
 (0)