Skip to content

Commit

Permalink
Query for length
Browse files Browse the repository at this point in the history
  • Loading branch information
hej2010 committed Feb 15, 2024
1 parent 2c79d42 commit 29107d4
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions parse/src/main/java/com/parse/ParseUriHttpBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import static com.parse.Parse.getApplicationContext;

import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.provider.OpenableColumns;

import com.parse.http.ParseHttpBody;

Expand All @@ -35,13 +37,24 @@ public ParseUriHttpBody(Uri uri, String contentType) {

private static long getUriLength(Uri uri) {
long length = -1;

Check warning on line 39 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#L39

Added line #L39 was not covered by tests
try {
ParcelFileDescriptor parcelFileDescriptor = getApplicationContext().getContentResolver().openFileDescriptor(uri, "r");
if (parcelFileDescriptor != null) {
length = parcelFileDescriptor.getStatSize();
parcelFileDescriptor.close();

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

Check warning on line 41 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#L41

Added line #L41 was not covered by tests
if (cursor != null && cursor.moveToFirst()) {
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);

Check warning on line 43 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#L43

Added line #L43 was not covered by tests
if (!cursor.isNull(sizeIndex)) {
length = cursor.getLong(sizeIndex);

Check warning on line 45 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#L45

Added line #L45 was not covered by tests
}
}
}
if (length == -1) {
try {
ParcelFileDescriptor parcelFileDescriptor = getApplicationContext().getContentResolver().openFileDescriptor(uri, "r");

Check warning on line 51 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#L51

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

Check warning on line 54 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-L54

Added lines #L53 - L54 were not covered by tests
}
} catch (IOException ignored) {
}

Check warning on line 57 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#L56-L57

Added lines #L56 - L57 were not covered by tests
} catch (IOException ignored) {
}
if (length == -1) {
try {
Expand Down

0 comments on commit 29107d4

Please sign in to comment.