Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Guava usage (CountingOutputStream) #43942

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.mockito)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.robolectric)
testImplementation(libs.thoughtworks)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.modules.network

import okhttp3.CookieJar

public interface CookieJarContainer : CookieJar {

public fun setCookieJar(cookieJar: CookieJar?)

public fun removeCookieJar()
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.modules.network

import okhttp3.OkHttpClient
import okhttp3.OkHttpClient.Builder

public fun interface CustomClientBuilder {
public fun apply(builder: OkHttpClient.Builder)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.modules.network

import java.io.FilterOutputStream
import java.io.IOException
import okhttp3.MediaType
import okhttp3.RequestBody
import okio.BufferedSink
import okio.Okio
import okio.Okio.sink
import okio.Sink

internal class ProgressRequestBody(
private val requestBody: RequestBody,
private val progressListener: ProgressListener
) : RequestBody() {

private var _contentLength = 0L

override fun contentType(): MediaType? = requestBody.contentType()

@Throws(IOException::class)
override fun contentLength(): Long {
if (_contentLength == 0L) {
_contentLength = requestBody.contentLength()
}
return _contentLength
}

@Throws(IOException::class)
override fun writeTo(sink: BufferedSink) {
// In 99% of cases, this method is called strictly once.
// The only case when it is called more than once is internal okhttp upload re-try.
// We need to re-create CountingOutputStream in this case as progress should be re-evaluated.
val sinkWrapper = Okio.buffer(outputStreamSink(sink))

// contentLength changes for input streams, since we're using inputStream.available(),
// so get the length before writing to the sink
contentLength()
requestBody.writeTo(sinkWrapper)
sinkWrapper.flush()
}

private fun outputStreamSink(sink: BufferedSink): Sink =
Okio.sink(
object : FilterOutputStream(sink.outputStream()) {
private var count = 0L

@Throws(IOException::class)
override fun write(b: ByteArray, off: Int, len: Int) {
super.write(b, off, len)
count += len.toLong()
sendProgressUpdate()
}

@Throws(IOException::class)
override fun write(b: Int) {
super.write(b)
count++
sendProgressUpdate()
}

@Throws(IOException::class)
private fun sendProgressUpdate() {
val bytesWritten = count
val contentLength = contentLength()
progressListener.onProgress(
bytesWritten, contentLength, bytesWritten == contentLength)
}
})
}
Loading
Loading