Skip to content

Commit 3e30326

Browse files
adrianhafacebook-github-bot
authored andcommitted
Remove okhttp internal util usage (#37843)
Summary: Remove okhttp internal `Util` usage so it can be compatible with [okhttp 5.0.0 alpha](https://square.github.io/okhttp/changelogs/changelog/#version-500-alpha7). ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [CHANGED] - Remove okhttp3 internal util usage Pull Request resolved: #37843 Test Plan: None, the implementation is based on okhttp internal util Reviewed By: NickGerleman Differential Revision: D46764363 Pulled By: cortinico fbshipit-source-id: e46770625f19057fa7374be15e92903d7966f880
1 parent b40bc79 commit 3e30326

File tree

1 file changed

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

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.zip.GZIPOutputStream;
3131
import okhttp3.MediaType;
3232
import okhttp3.RequestBody;
33-
import okhttp3.internal.Util;
3433
import okio.BufferedSink;
3534
import okio.ByteString;
3635
import okio.Okio;
@@ -128,6 +127,21 @@ private static InputStream getDownloadFileInputStream(Context context, Uri uri)
128127
return RequestBody.create(mediaType, gzipByteArrayOutputStream.toByteArray());
129128
}
130129

130+
/**
131+
* Reference:
132+
* https://github.com/square/okhttp/blob/8c8c3dbcfa91e28de2e13975ec414e07f153fde4/okhttp/src/commonMain/kotlin/okhttp3/internal/-UtilCommon.kt#L281-L288
133+
* Checked exceptions will be ignored
134+
*/
135+
private static void closeQuietly(Source source) {
136+
try {
137+
source.close();
138+
} catch (RuntimeException e) {
139+
throw e;
140+
} catch (Exception e) {
141+
// noop.
142+
}
143+
}
144+
131145
/** Creates a RequestBody from a mediaType and inputStream given. */
132146
public static RequestBody create(final MediaType mediaType, final InputStream inputStream) {
133147
return new RequestBody() {
@@ -152,7 +166,7 @@ public void writeTo(BufferedSink sink) throws IOException {
152166
source = Okio.source(inputStream);
153167
sink.writeAll(source);
154168
} finally {
155-
Util.closeQuietly(source);
169+
closeQuietly(source);
156170
}
157171
}
158172
};

0 commit comments

Comments
 (0)