From 52ec1d87e927efb933fade3de2411d3884d00c1b Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 27 Sep 2023 13:10:31 -0700 Subject: [PATCH] Remove support for Android API < 23 in RequestBodyUtil (#39672) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39672 Since minsdk version was increased to 23, we are deleting code using Android APIs < 23 for class RequestBodyUtil changelog: [Android][Breaking] Remove support for Android API < 23 in RequestBodyUtil Reviewed By: NickGerleman Differential Revision: D48545515 fbshipit-source-id: 8cc82a234cdb37304ad0d383ad57a7ce0de50a0e --- .../modules/network/RequestBodyUtil.java | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java index 7c0d07dde5b..eab727448f8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java @@ -11,7 +11,6 @@ import android.content.Context; 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; @@ -90,27 +89,11 @@ import okio.Source; 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); } }