diff --git a/okcurl/build.gradle.kts b/okcurl/build.gradle.kts index 68801c91a201..7580ada125d1 100644 --- a/okcurl/build.gradle.kts +++ b/okcurl/build.gradle.kts @@ -1,7 +1,6 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn import com.vanniktech.maven.publish.JavadocJar import com.vanniktech.maven.publish.KotlinJvm -import java.nio.charset.StandardCharsets import org.apache.tools.ant.taskdefs.condition.Os plugins { @@ -69,7 +68,7 @@ tasks.register("copyResourcesTemplates") { from("src/main/resources-templates") into("$buildDir/generated/resources-templates") expand("projectVersion" to "${project.version}") - filteringCharset = StandardCharsets.UTF_8.toString() + filteringCharset = Charsets.UTF_8.toString() }.let { tasks.processResources.dependsOn(it) tasks["javaSourcesJar"].dependsOn(it) diff --git a/okhttp-dnsoverhttps/src/main/kotlin/okhttp3/dnsoverhttps/DnsRecordCodec.kt b/okhttp-dnsoverhttps/src/main/kotlin/okhttp3/dnsoverhttps/DnsRecordCodec.kt index 62c679219639..367898be6488 100644 --- a/okhttp-dnsoverhttps/src/main/kotlin/okhttp3/dnsoverhttps/DnsRecordCodec.kt +++ b/okhttp-dnsoverhttps/src/main/kotlin/okhttp3/dnsoverhttps/DnsRecordCodec.kt @@ -18,7 +18,6 @@ package okhttp3.dnsoverhttps import java.io.EOFException import java.net.InetAddress import java.net.UnknownHostException -import java.nio.charset.StandardCharsets import okio.Buffer import okio.ByteString import okio.utf8Size @@ -32,7 +31,7 @@ object DnsRecordCodec { const val TYPE_A = 0x0001 const val TYPE_AAAA = 0x001c private const val TYPE_PTR = 0x000c - private val ASCII = StandardCharsets.US_ASCII + private val ASCII = Charsets.US_ASCII fun encodeQuery(host: String, type: Int): ByteString = Buffer().apply { writeShort(0) // query id diff --git a/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt b/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt index 0529b05d77e7..196585812297 100644 --- a/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt +++ b/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt @@ -17,9 +17,9 @@ package okhttp3.logging import java.io.IOException import java.nio.charset.Charset -import java.nio.charset.StandardCharsets.UTF_8 import java.util.TreeSet import java.util.concurrent.TimeUnit +import kotlin.text.Charsets.UTF_8 import okhttp3.Headers import okhttp3.Interceptor import okhttp3.OkHttpClient diff --git a/okhttp/build.gradle.kts b/okhttp/build.gradle.kts index 86ca62736889..b9b7023db9bd 100644 --- a/okhttp/build.gradle.kts +++ b/okhttp/build.gradle.kts @@ -1,7 +1,6 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn import com.vanniktech.maven.publish.JavadocJar import com.vanniktech.maven.publish.KotlinMultiplatform -import java.nio.charset.StandardCharsets import me.champeau.gradle.japicmp.JapicmpTask import org.jetbrains.kotlin.gradle.dsl.KotlinCompile @@ -246,7 +245,7 @@ val copyKotlinTemplates = tasks.register("copyKotlinTemplates") { from("src/commonMain/kotlinTemplates") into("$buildDir/generated/sources/kotlinTemplates") expand("projectVersion" to project.version) - filteringCharset = StandardCharsets.UTF_8.toString() + filteringCharset = Charsets.UTF_8.toString() } tasks.withType> { dependsOn(copyKotlinTemplates) diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt index bfd738acdd22..49b1f3eece12 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt @@ -16,10 +16,10 @@ package okhttp3 import java.nio.charset.Charset -import java.nio.charset.StandardCharsets.ISO_8859_1 import java.util.Collections.singletonMap import java.util.Collections.unmodifiableMap import java.util.Locale.US +import kotlin.text.Charsets.ISO_8859_1 /** * An [RFC 7235][rfc_7235] challenge. diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Credentials.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Credentials.kt index 33f676b52028..5ae99cc8287d 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Credentials.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Credentials.kt @@ -16,7 +16,7 @@ package okhttp3 import java.nio.charset.Charset -import java.nio.charset.StandardCharsets.ISO_8859_1 +import kotlin.text.Charsets.ISO_8859_1 import okio.ByteString.Companion.encode /** Factory for HTTP authorization credentials. */ diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt b/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt index 498c02efad8e..2b8723e82b8c 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt @@ -21,8 +21,8 @@ import java.net.URI import java.net.URISyntaxException import java.net.URL import java.nio.charset.Charset -import java.nio.charset.StandardCharsets.UTF_8 import java.util.Collections +import kotlin.text.Charsets.UTF_8 import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.internal.canParseAsIpAddress diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilJvm.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilJvm.kt index b591a517bec8..0149232843e2 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilJvm.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilJvm.kt @@ -22,16 +22,16 @@ import java.net.ServerSocket import java.net.Socket import java.net.SocketTimeoutException import java.nio.charset.Charset -import java.nio.charset.StandardCharsets.UTF_16BE -import java.nio.charset.StandardCharsets.UTF_16LE -import java.nio.charset.StandardCharsets.UTF_8 import java.util.Collections import java.util.Locale import java.util.TimeZone import java.util.concurrent.ThreadFactory import java.util.concurrent.TimeUnit +import kotlin.text.Charsets.UTF_16BE +import kotlin.text.Charsets.UTF_16LE import kotlin.text.Charsets.UTF_32BE import kotlin.text.Charsets.UTF_32LE +import kotlin.text.Charsets.UTF_8 import okhttp3.EventListener import okhttp3.Headers import okhttp3.Headers.Companion.headersOf diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt index 666277335e2d..ce3a606cbd7b 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt @@ -17,7 +17,6 @@ package okhttp3.internal.platform.android import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method -import java.nio.charset.StandardCharsets import javax.net.ssl.SSLSocket import okhttp3.Protocol import okhttp3.internal.platform.AndroidPlatform @@ -79,7 +78,7 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class) return try { val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray? - if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null + if (alpnResult != null) String(alpnResult, Charsets.UTF_8) else null } catch (e: NullPointerException) { // https://github.com/square/okhttp/issues/5587 when (e.message) { diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt index 2c65c286deee..e3188e18fc9d 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt @@ -18,9 +18,9 @@ package okhttp3.internal.publicsuffix import java.io.IOException import java.io.InterruptedIOException import java.net.IDN -import java.nio.charset.StandardCharsets.UTF_8 import java.util.concurrent.CountDownLatch import java.util.concurrent.atomic.AtomicBoolean +import kotlin.text.Charsets.UTF_8 import okhttp3.internal.and import okhttp3.internal.platform.Platform import okio.GzipSource diff --git a/okhttp/src/jvmTest/java/okhttp3/MediaTypeJvmTest.kt b/okhttp/src/jvmTest/java/okhttp3/MediaTypeJvmTest.kt index fd7f8e9ad6b4..d2e87b88c521 100644 --- a/okhttp/src/jvmTest/java/okhttp3/MediaTypeJvmTest.kt +++ b/okhttp/src/jvmTest/java/okhttp3/MediaTypeJvmTest.kt @@ -15,7 +15,6 @@ */ package okhttp3 -import java.nio.charset.StandardCharsets import java.util.* import kotlin.test.assertEquals import kotlin.test.assertNull @@ -39,17 +38,17 @@ class MediaTypeJvmTest: MediaTypeGetTest() { @Test fun testDefaultCharset() { val noCharset = parse("text/plain") assertEquals( - "UTF-8", noCharset.charset(StandardCharsets.UTF_8)!!.name() + "UTF-8", noCharset.charset(Charsets.UTF_8)!!.name() ) assertEquals( - "US-ASCII", noCharset.charset(StandardCharsets.US_ASCII)!!.name() + "US-ASCII", noCharset.charset(Charsets.US_ASCII)!!.name() ) val charset = parse("text/plain; charset=iso-8859-1") assertEquals( - "ISO-8859-1", charset.charset(StandardCharsets.UTF_8)!!.name() + "ISO-8859-1", charset.charset(Charsets.UTF_8)!!.name() ) assertEquals( - "ISO-8859-1", charset.charset(StandardCharsets.US_ASCII)!!.name() + "ISO-8859-1", charset.charset(Charsets.US_ASCII)!!.name() ) } diff --git a/okhttp/src/jvmTest/java/okhttp3/URLConnectionTest.kt b/okhttp/src/jvmTest/java/okhttp3/URLConnectionTest.kt index ef98abc02dc1..f7e3485f3c72 100644 --- a/okhttp/src/jvmTest/java/okhttp3/URLConnectionTest.kt +++ b/okhttp/src/jvmTest/java/okhttp3/URLConnectionTest.kt @@ -34,7 +34,6 @@ import java.net.SocketTimeoutException import java.net.URI import java.net.URLConnection import java.net.UnknownHostException -import java.nio.charset.StandardCharsets import java.security.KeyStore import java.security.cert.CertificateException import java.security.cert.X509Certificate @@ -2890,7 +2889,7 @@ class URLConnectionTest { } catch (expected: IllegalStateException) { } try { - sinkReference.get().write("ghi".toByteArray(StandardCharsets.UTF_8)) + sinkReference.get().write("ghi".toByteArray(Charsets.UTF_8)) sinkReference.get().emit() fail() } catch (expected: IllegalStateException) { diff --git a/okhttp/src/jvmTest/java/okhttp3/internal/http2/Http2ConnectionTest.kt b/okhttp/src/jvmTest/java/okhttp3/internal/http2/Http2ConnectionTest.kt index d97380beda0e..4f1593e15e16 100644 --- a/okhttp/src/jvmTest/java/okhttp3/internal/http2/Http2ConnectionTest.kt +++ b/okhttp/src/jvmTest/java/okhttp3/internal/http2/Http2ConnectionTest.kt @@ -18,10 +18,10 @@ package okhttp3.internal.http2 import java.io.EOFException import java.io.IOException import java.io.InterruptedIOException -import java.nio.charset.StandardCharsets.UTF_8 import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicInteger +import kotlin.text.Charsets.UTF_8 import okhttp3.Headers.Companion.headersOf import okhttp3.TestUtil.headerEntries import okhttp3.TestUtil.repeat diff --git a/okhttp/src/jvmTest/java/okhttp3/internal/http2/HttpOverHttp2Test.kt b/okhttp/src/jvmTest/java/okhttp3/internal/http2/HttpOverHttp2Test.kt index 52291b2e8991..1b66da39b6b2 100644 --- a/okhttp/src/jvmTest/java/okhttp3/internal/http2/HttpOverHttp2Test.kt +++ b/okhttp/src/jvmTest/java/okhttp3/internal/http2/HttpOverHttp2Test.kt @@ -19,7 +19,6 @@ import java.io.File import java.io.IOException import java.net.HttpURLConnection import java.net.SocketTimeoutException -import java.nio.charset.StandardCharsets import java.time.Duration import java.util.Arrays import java.util.concurrent.BlockingQueue @@ -243,7 +242,7 @@ class HttpOverHttp2Test { @ParameterizedTest @ArgumentsSource(ProtocolParamProvider::class) fun noDefaultContentLengthOnStreamingPost(protocol: Protocol, mockWebServer: MockWebServer) { setUp(protocol, mockWebServer) - val postBytes = "FGHIJ".toByteArray(StandardCharsets.UTF_8) + val postBytes = "FGHIJ".toByteArray(Charsets.UTF_8) server.enqueue(MockResponse().setBody("ABCDE")) val call = client.newCall( Request.Builder() @@ -268,7 +267,7 @@ class HttpOverHttp2Test { @ParameterizedTest @ArgumentsSource(ProtocolParamProvider::class) fun userSuppliedContentLengthHeader(protocol: Protocol, mockWebServer: MockWebServer) { setUp(protocol, mockWebServer) - val postBytes = "FGHIJ".toByteArray(StandardCharsets.UTF_8) + val postBytes = "FGHIJ".toByteArray(Charsets.UTF_8) server.enqueue(MockResponse().setBody("ABCDE")) val call = client.newCall( Request.Builder() @@ -299,7 +298,7 @@ class HttpOverHttp2Test { protocol: Protocol, mockWebServer: MockWebServer ) { setUp(protocol, mockWebServer) - val postBytes = "FGHIJ".toByteArray(StandardCharsets.UTF_8) + val postBytes = "FGHIJ".toByteArray(Charsets.UTF_8) server.enqueue(MockResponse().setBody("ABCDE")) val call = client.newCall( Request.Builder() diff --git a/okhttp/src/jvmTest/java/okhttp3/internal/tls/HostnameVerifierTest.kt b/okhttp/src/jvmTest/java/okhttp3/internal/tls/HostnameVerifierTest.kt index 0fc71db7953c..cd2f1adf5433 100644 --- a/okhttp/src/jvmTest/java/okhttp3/internal/tls/HostnameVerifierTest.kt +++ b/okhttp/src/jvmTest/java/okhttp3/internal/tls/HostnameVerifierTest.kt @@ -17,12 +17,12 @@ package okhttp3.internal.tls import java.io.ByteArrayInputStream -import java.nio.charset.StandardCharsets.UTF_8 import java.security.cert.CertificateFactory import java.security.cert.X509Certificate import java.util.stream.Stream import javax.net.ssl.SSLSession import javax.security.auth.x500.X500Principal +import kotlin.text.Charsets.UTF_8 import okhttp3.FakeSSLSession import okhttp3.OkHttpClient import okhttp3.internal.canParseAsIpAddress