Skip to content

Commit

Permalink
Spotless fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hej2010 committed Feb 16, 2024
1 parent 29107d4 commit 1c10476
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 91 deletions.
6 changes: 3 additions & 3 deletions parse/src/main/java/com/parse/ParseCountingUriHttpBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package com.parse;

import android.net.Uri;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -26,7 +25,7 @@ public ParseCountingUriHttpBody(Uri uri, ProgressCallback progressCallback) {
}

Check warning on line 25 in parse/src/main/java/com/parse/ParseCountingUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseCountingUriHttpBody.java#L24-L25

Added lines #L24 - L25 were not covered by tests

public ParseCountingUriHttpBody(
Uri uri, String contentType, ProgressCallback progressCallback) {
Uri uri, String contentType, ProgressCallback progressCallback) {
super(uri, contentType);
this.progressCallback = progressCallback;
}

Check warning on line 31 in parse/src/main/java/com/parse/ParseCountingUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseCountingUriHttpBody.java#L29-L31

Added lines #L29 - L31 were not covered by tests
Expand All @@ -37,7 +36,8 @@ public void writeTo(OutputStream output) throws IOException {
throw new IllegalArgumentException("Output stream may not be null");

Check warning on line 36 in parse/src/main/java/com/parse/ParseCountingUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseCountingUriHttpBody.java#L36

Added line #L36 was not covered by tests
}

final InputStream fileInput = Parse.getApplicationContext().getContentResolver().openInputStream(uri);
final InputStream fileInput =
Parse.getApplicationContext().getContentResolver().openInputStream(uri);

Check warning on line 40 in parse/src/main/java/com/parse/ParseCountingUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseCountingUriHttpBody.java#L40

Added line #L40 was not covered by tests
try {
byte[] buffer = new byte[DEFAULT_CHUNK_SIZE];

Check warning on line 42 in parse/src/main/java/com/parse/ParseCountingUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseCountingUriHttpBody.java#L42

Added line #L42 was not covered by tests
int n;
Expand Down
64 changes: 32 additions & 32 deletions parse/src/main/java/com/parse/ParseFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,38 +280,38 @@ private Task<Void> saveAsync(
return Task.cancelled();
}

Task<State> 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<State> saveTask;
if (data != null) {
saveTask =
getFileController()
.saveAsync(
state,
data,
sessionToken,
progressCallbackOnMainThread(
uploadProgressCallback),
cancellationToken);
} else if (uri != null) {
saveTask =
getFileController()
.saveAsync(

Check warning on line 297 in parse/src/main/java/com/parse/ParseFile.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFile.java#L296-L297

Added lines #L296 - L297 were not covered by tests
state,
uri,
sessionToken,
progressCallbackOnMainThread(

Check warning on line 301 in parse/src/main/java/com/parse/ParseFile.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFile.java#L301

Added line #L301 was not covered by tests
uploadProgressCallback),
cancellationToken);
} else {
saveTask =
getFileController()
.saveAsync(
state,
file,
sessionToken,
progressCallbackOnMainThread(
uploadProgressCallback),
cancellationToken);
}

return saveTask.onSuccessTask(
task1 -> {
Expand Down
59 changes: 29 additions & 30 deletions parse/src/main/java/com/parse/ParseFileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,11 +165,11 @@ public Task<ParseFile.State> saveAsync(
}

public Task<ParseFile.State> saveAsync(
final ParseFile.State state,
final Uri uri,
String sessionToken,
ProgressCallback uploadProgressCallback,
Task<Void> cancellationToken) {
final ParseFile.State state,
final Uri uri,
String sessionToken,
ProgressCallback uploadProgressCallback,
Task<Void> cancellationToken) {
if (state.url() != null) { // !isDirty
return Task.forResult(state);

Check warning on line 174 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L174

Added line #L174 was not covered by tests
}
Expand All @@ -179,33 +178,33 @@ public Task<ParseFile.State> saveAsync(
}

final ParseRESTCommand command =

Check warning on line 180 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L180

Added line #L180 was not covered by tests
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();

Check warning on line 186 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L182-L186

Added lines #L182 - L186 were not covered by tests

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(

Check warning on line 189 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L188-L189

Added lines #L188 - L189 were not covered by tests
task -> {
JSONObject result = task.getResult();
ParseFile.State newState =

Check warning on line 192 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L191-L192

Added lines #L191 - L192 were not covered by tests
new ParseFile.State.Builder(state)
.name(result.getString("name"))
.url(result.getString("url"))
.build();

Check warning on line 196 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L194-L196

Added lines #L194 - L196 were not covered by tests

return newState;
},
ParseExecutors.io());
// Write data to cache
try {
ParseFileUtils.writeUriToFile(getCacheFile(newState), uri);
} catch (IOException e) {

Check warning on line 201 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L200-L201

Added lines #L200 - L201 were not covered by tests
// do nothing
}

Check warning on line 203 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L203

Added line #L203 was not covered by tests

return newState;

Check warning on line 205 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L205

Added line #L205 was not covered by tests
},
ParseExecutors.io());

Check warning on line 207 in parse/src/main/java/com/parse/ParseFileController.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseFileController.java#L207

Added line #L207 was not covered by tests
}

public Task<File> fetchAsync(
Expand Down
9 changes: 3 additions & 6 deletions parse/src/main/java/com/parse/ParseFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion parse/src/main/java/com/parse/ParseRESTFileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions parse/src/main/java/com/parse/ParseUriHttpBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +36,10 @@ public ParseUriHttpBody(Uri uri, String contentType) {
private static long getUriLength(Uri uri) {
long length = -1;

Check warning on line 37 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L37

Added line #L37 was not covered by tests

try (Cursor cursor = getApplicationContext().getContentResolver().query(uri, null, null, null, null, null)) {
try (Cursor cursor =
getApplicationContext()
.getContentResolver()
.query(uri, null, null, null, null, null)) {

Check warning on line 42 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L40-L42

Added lines #L40 - L42 were not covered by tests
if (cursor != null && cursor.moveToFirst()) {
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);

Check warning on line 44 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L44

Added line #L44 was not covered by tests
if (!cursor.isNull(sizeIndex)) {
Expand All @@ -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");

Check warning on line 53 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L53

Added line #L53 was not covered by tests
if (parcelFileDescriptor != null) {
length = parcelFileDescriptor.getStatSize();
parcelFileDescriptor.close();

Check warning on line 56 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L55-L56

Added lines #L55 - L56 were not covered by tests
Expand All @@ -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");

Check warning on line 66 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L64-L66

Added lines #L64 - L66 were not covered by tests
if (assetFileDescriptor != null) {
length = assetFileDescriptor.getLength();
assetFileDescriptor.close();

Check warning on line 69 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L68-L69

Added lines #L68 - L69 were not covered by tests
Expand All @@ -80,7 +85,8 @@ public void writeTo(OutputStream out) throws IOException {
throw new IllegalArgumentException("Output stream can not be null");

Check warning on line 85 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L85

Added line #L85 was not covered by tests
}

final InputStream fileInput = getApplicationContext().getContentResolver().openInputStream(uri);
final InputStream fileInput =
getApplicationContext().getContentResolver().openInputStream(uri);

Check warning on line 89 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L89

Added line #L89 was not covered by tests
try {
ParseIOUtils.copy(fileInput, out);

Check warning on line 91 in parse/src/main/java/com/parse/ParseUriHttpBody.java

View check run for this annotation

Codecov / codecov/patch

parse/src/main/java/com/parse/ParseUriHttpBody.java#L91

Added line #L91 was not covered by tests
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
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;
import java.io.IOException;
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 {

Expand Down
1 change: 0 additions & 1 deletion parse/src/test/java/com/parse/ParseFileControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions parse/src/test/java/com/parse/ParseUriHttpBodyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1c10476

Please sign in to comment.