From 1c10476208ac320aff351f7cef0db62fe6f3186a Mon Sep 17 00:00:00 2001 From: Rikard Teodorsson <9367038+hej2010@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:46:02 +0100 Subject: [PATCH] Spotless fix --- .../com/parse/ParseCountingUriHttpBody.java | 6 +- parse/src/main/java/com/parse/ParseFile.java | 64 +++++++++---------- .../java/com/parse/ParseFileController.java | 59 +++++++++-------- .../main/java/com/parse/ParseFileUtils.java | 9 +-- .../java/com/parse/ParseRESTFileCommand.java | 1 - .../main/java/com/parse/ParseUriHttpBody.java | 18 ++++-- .../parse/ParseCountingUriHttpBodyTest.java | 8 +-- .../com/parse/ParseFileControllerTest.java | 1 - .../java/com/parse/ParseUriHttpBodyTest.java | 11 ++-- 9 files changed, 86 insertions(+), 91 deletions(-) diff --git a/parse/src/main/java/com/parse/ParseCountingUriHttpBody.java b/parse/src/main/java/com/parse/ParseCountingUriHttpBody.java index 87bf355a..0b0858b6 100644 --- a/parse/src/main/java/com/parse/ParseCountingUriHttpBody.java +++ b/parse/src/main/java/com/parse/ParseCountingUriHttpBody.java @@ -9,7 +9,6 @@ package com.parse; import android.net.Uri; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -26,7 +25,7 @@ public ParseCountingUriHttpBody(Uri uri, ProgressCallback progressCallback) { } public ParseCountingUriHttpBody( - Uri uri, String contentType, ProgressCallback progressCallback) { + Uri uri, String contentType, ProgressCallback progressCallback) { super(uri, contentType); this.progressCallback = progressCallback; } @@ -37,7 +36,8 @@ public void writeTo(OutputStream output) throws IOException { throw new IllegalArgumentException("Output stream may not be null"); } - final InputStream fileInput = Parse.getApplicationContext().getContentResolver().openInputStream(uri); + final InputStream fileInput = + Parse.getApplicationContext().getContentResolver().openInputStream(uri); try { byte[] buffer = new byte[DEFAULT_CHUNK_SIZE]; int n; diff --git a/parse/src/main/java/com/parse/ParseFile.java b/parse/src/main/java/com/parse/ParseFile.java index f79291ce..76a95e07 100644 --- a/parse/src/main/java/com/parse/ParseFile.java +++ b/parse/src/main/java/com/parse/ParseFile.java @@ -280,38 +280,38 @@ private Task saveAsync( return Task.cancelled(); } - Task saveTask; - if (data != null) { - saveTask = - getFileController() - .saveAsync( - state, - data, - sessionToken, - progressCallbackOnMainThread( - uploadProgressCallback), - cancellationToken); - } else if (uri != null) { - saveTask = - getFileController() - .saveAsync( - state, - uri, - sessionToken, - progressCallbackOnMainThread( - uploadProgressCallback), - cancellationToken); - } else { - saveTask = - getFileController() - .saveAsync( - state, - file, - sessionToken, - progressCallbackOnMainThread( - uploadProgressCallback), - cancellationToken); - } + Task saveTask; + if (data != null) { + saveTask = + getFileController() + .saveAsync( + state, + data, + sessionToken, + progressCallbackOnMainThread( + uploadProgressCallback), + cancellationToken); + } else if (uri != null) { + saveTask = + getFileController() + .saveAsync( + state, + uri, + sessionToken, + progressCallbackOnMainThread( + uploadProgressCallback), + cancellationToken); + } else { + saveTask = + getFileController() + .saveAsync( + state, + file, + sessionToken, + progressCallbackOnMainThread( + uploadProgressCallback), + cancellationToken); + } return saveTask.onSuccessTask( task1 -> { diff --git a/parse/src/main/java/com/parse/ParseFileController.java b/parse/src/main/java/com/parse/ParseFileController.java index 44118bcd..17016ae5 100644 --- a/parse/src/main/java/com/parse/ParseFileController.java +++ b/parse/src/main/java/com/parse/ParseFileController.java @@ -9,7 +9,6 @@ package com.parse; import android.net.Uri; - import com.parse.boltsinternal.Task; import com.parse.http.ParseHttpRequest; import java.io.File; @@ -166,11 +165,11 @@ public Task saveAsync( } public Task saveAsync( - final ParseFile.State state, - final Uri uri, - String sessionToken, - ProgressCallback uploadProgressCallback, - Task cancellationToken) { + final ParseFile.State state, + final Uri uri, + String sessionToken, + ProgressCallback uploadProgressCallback, + Task cancellationToken) { if (state.url() != null) { // !isDirty return Task.forResult(state); } @@ -179,33 +178,33 @@ public Task saveAsync( } final ParseRESTCommand command = - new ParseRESTFileCommand.Builder() - .fileName(state.name()) - .uri(uri) - .contentType(state.mimeType()) - .sessionToken(sessionToken) - .build(); + new ParseRESTFileCommand.Builder() + .fileName(state.name()) + .uri(uri) + .contentType(state.mimeType()) + .sessionToken(sessionToken) + .build(); return command.executeAsync(restClient, uploadProgressCallback, null, cancellationToken) - .onSuccess( - task -> { - JSONObject result = task.getResult(); - ParseFile.State newState = - new ParseFile.State.Builder(state) - .name(result.getString("name")) - .url(result.getString("url")) - .build(); - - // Write data to cache - try { - ParseFileUtils.writeUriToFile(getCacheFile(newState), uri); - } catch (IOException e) { - // do nothing - } + .onSuccess( + task -> { + JSONObject result = task.getResult(); + ParseFile.State newState = + new ParseFile.State.Builder(state) + .name(result.getString("name")) + .url(result.getString("url")) + .build(); - return newState; - }, - ParseExecutors.io()); + // Write data to cache + try { + ParseFileUtils.writeUriToFile(getCacheFile(newState), uri); + } catch (IOException e) { + // do nothing + } + + return newState; + }, + ParseExecutors.io()); } public Task fetchAsync( diff --git a/parse/src/main/java/com/parse/ParseFileUtils.java b/parse/src/main/java/com/parse/ParseFileUtils.java index b7198fee..c48f7b51 100644 --- a/parse/src/main/java/com/parse/ParseFileUtils.java +++ b/parse/src/main/java/com/parse/ParseFileUtils.java @@ -17,12 +17,7 @@ package com.parse; import android.net.Uri; - import androidx.annotation.NonNull; - -import org.json.JSONException; -import org.json.JSONObject; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -33,6 +28,8 @@ import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.util.List; +import org.json.JSONException; +import org.json.JSONObject; /** General file manipulation utilities. */ public class ParseFileUtils { @@ -126,7 +123,7 @@ public static void writeByteArrayToFile(File file, byte[] data) throws IOExcepti * exist. * * @param file the file to write to - * @param uri the content uri with data to write to the file + * @param uri the content uri with data to write to the file * @throws IOException in case of an I/O error * @since Commons IO 1.1 */ diff --git a/parse/src/main/java/com/parse/ParseRESTFileCommand.java b/parse/src/main/java/com/parse/ParseRESTFileCommand.java index 1826747e..63db546c 100644 --- a/parse/src/main/java/com/parse/ParseRESTFileCommand.java +++ b/parse/src/main/java/com/parse/ParseRESTFileCommand.java @@ -9,7 +9,6 @@ package com.parse; import android.net.Uri; - import com.parse.http.ParseHttpBody; import com.parse.http.ParseHttpRequest; import java.io.File; diff --git a/parse/src/main/java/com/parse/ParseUriHttpBody.java b/parse/src/main/java/com/parse/ParseUriHttpBody.java index 89c00ffb..c6ab7748 100644 --- a/parse/src/main/java/com/parse/ParseUriHttpBody.java +++ b/parse/src/main/java/com/parse/ParseUriHttpBody.java @@ -15,9 +15,7 @@ import android.net.Uri; import android.os.ParcelFileDescriptor; import android.provider.OpenableColumns; - import com.parse.http.ParseHttpBody; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -38,7 +36,10 @@ public ParseUriHttpBody(Uri uri, String contentType) { private static long getUriLength(Uri uri) { long length = -1; - try (Cursor cursor = getApplicationContext().getContentResolver().query(uri, null, null, null, null, null)) { + try (Cursor cursor = + getApplicationContext() + .getContentResolver() + .query(uri, null, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); if (!cursor.isNull(sizeIndex)) { @@ -48,7 +49,8 @@ private static long getUriLength(Uri uri) { } if (length == -1) { try { - ParcelFileDescriptor parcelFileDescriptor = getApplicationContext().getContentResolver().openFileDescriptor(uri, "r"); + ParcelFileDescriptor parcelFileDescriptor = + getApplicationContext().getContentResolver().openFileDescriptor(uri, "r"); if (parcelFileDescriptor != null) { length = parcelFileDescriptor.getStatSize(); parcelFileDescriptor.close(); @@ -58,7 +60,10 @@ private static long getUriLength(Uri uri) { } if (length == -1) { try { - AssetFileDescriptor assetFileDescriptor = getApplicationContext().getContentResolver().openAssetFileDescriptor(uri, "r"); + AssetFileDescriptor assetFileDescriptor = + getApplicationContext() + .getContentResolver() + .openAssetFileDescriptor(uri, "r"); if (assetFileDescriptor != null) { length = assetFileDescriptor.getLength(); assetFileDescriptor.close(); @@ -80,7 +85,8 @@ public void writeTo(OutputStream out) throws IOException { throw new IllegalArgumentException("Output stream can not be null"); } - final InputStream fileInput = getApplicationContext().getContentResolver().openInputStream(uri); + final InputStream fileInput = + getApplicationContext().getContentResolver().openInputStream(uri); try { ParseIOUtils.copy(fileInput, out); } finally { diff --git a/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java b/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java index 8175a644..777851e5 100644 --- a/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java +++ b/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java @@ -13,11 +13,6 @@ import static org.junit.Assert.fail; import android.net.Uri; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; @@ -25,6 +20,9 @@ import java.util.Arrays; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; public class ParseCountingUriHttpBodyTest { diff --git a/parse/src/test/java/com/parse/ParseFileControllerTest.java b/parse/src/test/java/com/parse/ParseFileControllerTest.java index 108cc8d2..7bc9c829 100644 --- a/parse/src/test/java/com/parse/ParseFileControllerTest.java +++ b/parse/src/test/java/com/parse/ParseFileControllerTest.java @@ -21,7 +21,6 @@ import static org.mockito.Mockito.when; import android.net.Uri; - import com.parse.boltsinternal.Task; import com.parse.http.ParseHttpRequest; import com.parse.http.ParseHttpResponse; diff --git a/parse/src/test/java/com/parse/ParseUriHttpBodyTest.java b/parse/src/test/java/com/parse/ParseUriHttpBodyTest.java index e0e837b2..8e472195 100644 --- a/parse/src/test/java/com/parse/ParseUriHttpBodyTest.java +++ b/parse/src/test/java/com/parse/ParseUriHttpBodyTest.java @@ -12,18 +12,15 @@ import static org.junit.Assert.assertEquals; import android.net.Uri; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; public class ParseUriHttpBodyTest { - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Test public void testInitializeWithUri() throws IOException {