Skip to content

Commit 03b9b52

Browse files
adrianhakelset
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 a46a7cd commit 03b9b52

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
@@ -29,7 +29,6 @@
2929
import java.util.zip.GZIPOutputStream;
3030
import okhttp3.MediaType;
3131
import okhttp3.RequestBody;
32-
import okhttp3.internal.Util;
3332
import okio.BufferedSink;
3433
import okio.ByteString;
3534
import okio.Okio;
@@ -122,6 +121,21 @@ private static InputStream getDownloadFileInputStream(Context context, Uri uri)
122121
return RequestBody.create(mediaType, gzipByteArrayOutputStream.toByteArray());
123122
}
124123

124+
/**
125+
* Reference:
126+
* https://github.com/square/okhttp/blob/8c8c3dbcfa91e28de2e13975ec414e07f153fde4/okhttp/src/commonMain/kotlin/okhttp3/internal/-UtilCommon.kt#L281-L288
127+
* Checked exceptions will be ignored
128+
*/
129+
private static void closeQuietly(Source source) {
130+
try {
131+
source.close();
132+
} catch (RuntimeException e) {
133+
throw e;
134+
} catch (Exception e) {
135+
// noop.
136+
}
137+
}
138+
125139
/** Creates a RequestBody from a mediaType and inputStream given. */
126140
public static RequestBody create(final MediaType mediaType, final InputStream inputStream) {
127141
return new RequestBody() {
@@ -146,7 +160,7 @@ public void writeTo(BufferedSink sink) throws IOException {
146160
source = Okio.source(inputStream);
147161
sink.writeAll(source);
148162
} finally {
149-
Util.closeQuietly(source);
163+
closeQuietly(source);
150164
}
151165
}
152166
};

0 commit comments

Comments
 (0)