From 7730b9dd1d964f651702a24fffde4c9231736e24 Mon Sep 17 00:00:00 2001 From: Adrian Hartanto Date: Wed, 14 Jun 2023 10:34:19 +0700 Subject: [PATCH] silence exception --- .../react/modules/network/RequestBodyUtil.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 462bd12f107218..2f8b14716ff097 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 @@ -127,6 +127,14 @@ private static InputStream getDownloadFileInputStream(Context context, Uri uri) return RequestBody.create(mediaType, gzipByteArrayOutputStream.toByteArray()); } + private static void closeQuietly(Source source) { + try { + source.close(); + } catch (IOException e) { + // noop. + } + } + /** Creates a RequestBody from a mediaType and inputStream given. */ public static RequestBody create(final MediaType mediaType, final InputStream inputStream) { return new RequestBody() { @@ -151,7 +159,7 @@ public void writeTo(BufferedSink sink) throws IOException { source = Okio.source(inputStream); sink.writeAll(source); } finally { - source.close(); + closeQuietly(source); } } };