Skip to content

Commit 52ec1d8

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Remove support for Android API < 23 in RequestBodyUtil (#39672)
Summary: Pull Request resolved: #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
1 parent c359a44 commit 52ec1d8

File tree

1 file changed

+5
-22
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network

1 file changed

+5
-22
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import android.graphics.Bitmap;
1212
import android.graphics.BitmapFactory;
1313
import android.net.Uri;
14-
import android.os.Build;
1514
import android.util.Base64;
1615
import androidx.annotation.Nullable;
1716
import com.facebook.common.logging.FLog;
@@ -90,27 +89,11 @@ private static InputStream getDownloadFileInputStream(Context context, Uri uri)
9089
file.deleteOnExit();
9190

9291
final URL url = new URL(uri.toString());
93-
final InputStream is = url.openStream();
94-
try {
95-
final ReadableByteChannel channel = Channels.newChannel(is);
96-
try {
97-
final FileOutputStream stream = new FileOutputStream(file);
98-
try {
99-
long maxBytes = Long.MAX_VALUE;
100-
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
101-
// Old version of Android internally cast value to integer
102-
maxBytes = (long) Integer.MAX_VALUE;
103-
}
104-
stream.getChannel().transferFrom(channel, 0, maxBytes);
105-
return new FileInputStream(file);
106-
} finally {
107-
stream.close();
108-
}
109-
} finally {
110-
channel.close();
111-
}
112-
} finally {
113-
is.close();
92+
try (FileOutputStream stream = new FileOutputStream(file);
93+
InputStream is = url.openStream();
94+
ReadableByteChannel channel = Channels.newChannel(is)) {
95+
stream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
96+
return new FileInputStream(file);
11497
}
11598
}
11699

0 commit comments

Comments
 (0)