Skip to content

Commit

Permalink
Replace StandardCharsets with Charsets in Kotlin (square#6986)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Jan 8, 2022
1 parent 3854af9 commit 5cfc040
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 29 deletions.
3 changes: 1 addition & 2 deletions okcurl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -69,7 +68,7 @@ tasks.register<Copy>("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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -246,7 +245,7 @@ val copyKotlinTemplates = tasks.register<Copy>("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<KotlinCompile<*>> {
dependsOn(copyKotlinTemplates)
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/jvmMain/kotlin/okhttp3/Credentials.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +78,7 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class<in SSLSocket>)

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions okhttp/src/jvmTest/java/okhttp3/MediaTypeJvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package okhttp3

import java.nio.charset.StandardCharsets
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertNull
Expand All @@ -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()
)
}

Expand Down
3 changes: 1 addition & 2 deletions okhttp/src/jvmTest/java/okhttp3/URLConnectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Any>()
} catch (expected: IllegalStateException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cfc040

Please sign in to comment.