Skip to content

Commit

Permalink
Remove support for Android API < 23 in RequestBodyUtil
Browse files Browse the repository at this point in the history
Summary:
Since minsdk version was increased to 23, we are deleting code using Android APIs < 23 for class RequestBodyUtil

chnagelog: [Android][Breaking] Remove support for Android API < 23 in RequestBodyUtil

Differential Revision: D48545515

fbshipit-source-id: fc48c19ae99cab1d82c180e73dcd7af5afcd40e8
  • Loading branch information
mdvacca authored and facebook-github-bot committed Sep 26, 2023
1 parent b44e683 commit 11acec4
Showing 1 changed file with 5 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.util.Base64;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
Expand Down Expand Up @@ -90,27 +89,11 @@ private static InputStream getDownloadFileInputStream(Context context, Uri uri)
file.deleteOnExit();

final URL url = new URL(uri.toString());
final InputStream is = url.openStream();
try {
final ReadableByteChannel channel = Channels.newChannel(is);
try {
final FileOutputStream stream = new FileOutputStream(file);
try {
long maxBytes = Long.MAX_VALUE;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
// Old version of Android internally cast value to integer
maxBytes = (long) Integer.MAX_VALUE;
}
stream.getChannel().transferFrom(channel, 0, maxBytes);
return new FileInputStream(file);
} finally {
stream.close();
}
} finally {
channel.close();
}
} finally {
is.close();
try (FileOutputStream stream = new FileOutputStream(file);
InputStream is = url.openStream();
ReadableByteChannel channel = Channels.newChannel(is)) {
stream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
return new FileInputStream(file);
}
}

Expand Down

0 comments on commit 11acec4

Please sign in to comment.