Skip to content

Commit

Permalink
Merge pull request square#5080 from square/jakew/smattering-of-kotlin…
Browse files Browse the repository at this point in the history
…/2019-05-20

Eliminate Util object in favor of top-level functions
  • Loading branch information
squarejesse authored May 20, 2019
2 parents 032716b + 450750c commit 0718352
Show file tree
Hide file tree
Showing 45 changed files with 338 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import okhttp3.HttpUrl
import okhttp3.Protocol
import okhttp3.Request
import okhttp3.Response
import okhttp3.internal.Util
import okhttp3.internal.addHeaderLenient
import okhttp3.internal.closeQuietly
import okhttp3.internal.duplex.MwsDuplexAccess
Expand All @@ -34,6 +33,7 @@ import okhttp3.internal.http2.Http2Connection
import okhttp3.internal.http2.Http2Stream
import okhttp3.internal.immutableListOf
import okhttp3.internal.platform.Platform
import okhttp3.internal.threadFactory
import okhttp3.internal.toImmutableList
import okhttp3.internal.ws.RealWebSocket
import okhttp3.internal.ws.WebSocketProtocol
Expand Down Expand Up @@ -318,7 +318,7 @@ class MockWebServer : ExternalResource(), Closeable {
require(!started) { "start() already called" }
started = true

executor = Executors.newCachedThreadPool(Util.threadFactory("MockWebServer", false))
executor = Executors.newCachedThreadPool(threadFactory("MockWebServer", false))
this.inetSocketAddress = inetSocketAddress

if (serverSocketFactory == null) {
Expand Down
6 changes: 3 additions & 3 deletions okcurl/src/main/java/okhttp3/curl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import okhttp3.Protocol
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.curl.Main.Companion.NAME
import okhttp3.internal.Util
import okhttp3.internal.format
import okhttp3.internal.http.StatusLine
import okhttp3.internal.http2.Http2
import okhttp3.internal.platform.Platform
Expand Down Expand Up @@ -268,11 +268,11 @@ class Main : Runnable {
level = Level.FINE
formatter = object : SimpleFormatter() {
override fun format(record: LogRecord): String {
return Util.format("%s%n", record.message)
return format("%s%n", record.message)
}
}
})
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.internal.EMPTY_RESPONSE
import okhttp3.internal.Internal
import okhttp3.internal.Util
import okhttp3.sse.EventSource
import okhttp3.sse.EventSourceListener
import java.io.IOException
Expand Down Expand Up @@ -66,7 +66,7 @@ class RealEventSource(

// Replace the body with an empty one so the callbacks can't see real data.
val response = response.newBuilder()
.body(Util.EMPTY_RESPONSE)
.body(EMPTY_RESPONSE)
.build()

val reader = ServerSentEventReader(body.source(), this)
Expand Down
4 changes: 2 additions & 2 deletions okhttp-tls/src/main/java/okhttp3/tls/HandshakeCertificates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package okhttp3.tls

import okhttp3.CertificatePinner
import okhttp3.internal.Util
import okhttp3.internal.platform.Platform
import okhttp3.internal.platformTrustManager
import okhttp3.tls.internal.TlsUtil.newKeyManager
import okhttp3.tls.internal.TlsUtil.newTrustManager
import java.security.SecureRandom
Expand Down Expand Up @@ -126,7 +126,7 @@ class HandshakeCertificates private constructor(
* this problem with [certificate pinning][CertificatePinner].
*/
fun addPlatformTrustedCertificates() = apply {
val platformTrustManager = Util.platformTrustManager()
val platformTrustManager = platformTrustManager()
Collections.addAll(trustedCertificates, *platformTrustManager.acceptedIssuers)
}

Expand Down
2 changes: 1 addition & 1 deletion okhttp-tls/src/main/java/okhttp3/tls/HeldCertificate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package okhttp3.tls

import okhttp3.internal.Util.verifyAsIpAddress
import okhttp3.internal.verifyAsIpAddress
import okio.ByteString
import okio.ByteString.Companion.toByteString
import org.bouncycastle.asn1.ASN1Encodable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package okhttp3

import okhttp3.internal.Util.delimiterOffset
import okhttp3.internal.Util.trimSubstring
import okhttp3.internal.delimiterOffset
import okhttp3.internal.trimSubstring
import okhttp3.internal.cookieToString
import okhttp3.internal.platform.Platform
import okhttp3.internal.platform.Platform.Companion.WARN
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/java/okhttp3/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package okhttp3

import okhttp3.internal.Util
import okhttp3.internal.EMPTY_HEADERS
import okhttp3.internal.addHeaderLenient
import okhttp3.internal.cache.CacheRequest
import okhttp3.internal.cache.CacheStrategy
Expand Down Expand Up @@ -792,7 +792,7 @@ class Cache internal constructor(
*/
private fun varyHeaders(requestHeaders: Headers, responseHeaders: Headers): Headers {
val varyFields = responseHeaders.varyFields()
if (varyFields.isEmpty()) return Util.EMPTY_HEADERS
if (varyFields.isEmpty()) return EMPTY_HEADERS

val result = Headers.Builder()
for (i in 0 until requestHeaders.size) {
Expand Down
8 changes: 4 additions & 4 deletions okhttp/src/main/java/okhttp3/ConnectionSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package okhttp3

import okhttp3.ConnectionSpec.Builder
import okhttp3.internal.Util.concat
import okhttp3.internal.Util.indexOf
import okhttp3.internal.Util.intersect
import okhttp3.internal.Util.nonEmptyIntersection
import okhttp3.internal.concat
import okhttp3.internal.indexOf
import okhttp3.internal.intersect
import okhttp3.internal.nonEmptyIntersection
import java.util.Arrays
import java.util.Objects
import javax.net.ssl.SSLSocket
Expand Down
10 changes: 5 additions & 5 deletions okhttp/src/main/java/okhttp3/Cookie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package okhttp3

import okhttp3.internal.Util.UTC
import okhttp3.internal.Util.delimiterOffset
import okhttp3.internal.Util.indexOfControlOrNonAscii
import okhttp3.internal.Util.trimSubstring
import okhttp3.internal.Util.verifyAsIpAddress
import okhttp3.internal.UTC
import okhttp3.internal.delimiterOffset
import okhttp3.internal.indexOfControlOrNonAscii
import okhttp3.internal.trimSubstring
import okhttp3.internal.verifyAsIpAddress
import okhttp3.internal.http.HttpDate
import okhttp3.internal.publicsuffix.PublicSuffixDatabase
import okhttp3.internal.toCanonicalHost
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/java/okhttp3/Dispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package okhttp3

import okhttp3.RealCall.AsyncCall
import okhttp3.internal.Util
import okhttp3.internal.threadFactory
import java.util.ArrayDeque
import java.util.ArrayList
import java.util.Collections
Expand Down Expand Up @@ -92,7 +92,7 @@ class Dispatcher constructor() {
@Synchronized fun executorService(): ExecutorService {
if (executorService == null) {
executorService = ThreadPoolExecutor(0, Int.MAX_VALUE, 60, TimeUnit.SECONDS,
SynchronousQueue(), Util.threadFactory("OkHttp Dispatcher", false))
SynchronousQueue(), threadFactory("OkHttp Dispatcher", false))
}
return executorService!!
}
Expand Down
6 changes: 3 additions & 3 deletions okhttp/src/main/java/okhttp3/Headers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package okhttp3

import okhttp3.Headers.Builder
import okhttp3.internal.Util
import okhttp3.internal.format
import okhttp3.internal.http.HttpDate
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
import java.time.Instant
Expand Down Expand Up @@ -405,7 +405,7 @@ class Headers private constructor(
for (i in 0 until name.length) {
val c = name[i]
require(c in '\u0021'..'\u007e') {
Util.format("Unexpected char %#04x at %d in header name: %s", c.toInt(), i, name)
format("Unexpected char %#04x at %d in header name: %s", c.toInt(), i, name)
}
}
}
Expand All @@ -414,7 +414,7 @@ class Headers private constructor(
for (i in 0 until value.length) {
val c = value[i]
require(c == '\t' || c in '\u0020'..'\u007e') {
Util.format("Unexpected char %#04x at %d in %s value: %s", c.toInt(), i, name, value)
format("Unexpected char %#04x at %d in %s value: %s", c.toInt(), i, name, value)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions okhttp/src/main/java/okhttp3/HttpUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package okhttp3

import okhttp3.HttpUrl.Companion.get
import okhttp3.HttpUrl.Companion.parse
import okhttp3.internal.Util.decodeHexDigit
import okhttp3.internal.Util.delimiterOffset
import okhttp3.internal.Util.skipLeadingAsciiWhitespace
import okhttp3.internal.Util.skipTrailingAsciiWhitespace
import okhttp3.internal.Util.verifyAsIpAddress
import okhttp3.internal.decodeHexDigit
import okhttp3.internal.delimiterOffset
import okhttp3.internal.skipLeadingAsciiWhitespace
import okhttp3.internal.skipTrailingAsciiWhitespace
import okhttp3.internal.verifyAsIpAddress
import okhttp3.internal.publicsuffix.PublicSuffixDatabase
import okhttp3.internal.toCanonicalHost
import okio.Buffer
Expand Down
11 changes: 6 additions & 5 deletions okhttp/src/main/java/okhttp3/OkHttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package okhttp3

import okhttp3.Protocol.HTTP_1_1
import okhttp3.Protocol.HTTP_2
import okhttp3.internal.Util
import okhttp3.internal.Util.checkDuration
import okhttp3.internal.checkDuration
import okhttp3.internal.cache.InternalCache
import okhttp3.internal.eventListenerFactory
import okhttp3.internal.toImmutableList
import okhttp3.internal.immutableListOf
import okhttp3.internal.platform.Platform
import okhttp3.internal.platformTrustManager
import okhttp3.internal.proxy.NullProxySelector
import okhttp3.internal.tls.CertificateChainCleaner
import okhttp3.internal.tls.OkHostnameVerifier
Expand Down Expand Up @@ -163,7 +164,7 @@ open class OkHttpClient internal constructor(
this.sslSocketFactory = builder.sslSocketFactory
this.certificateChainCleaner = builder.certificateChainCleaner
} else {
val trustManager = Util.platformTrustManager()
val trustManager = platformTrustManager()
Platform.get().configureTrustManager(trustManager)
this.sslSocketFactory = newSslSocketFactory(trustManager)
this.certificateChainCleaner = CertificateChainCleaner.get(trustManager)
Expand Down Expand Up @@ -279,7 +280,7 @@ open class OkHttpClient internal constructor(
internal var connectionSpecs: List<ConnectionSpec> = DEFAULT_CONNECTION_SPECS
internal val interceptors: MutableList<Interceptor> = mutableListOf()
internal val networkInterceptors: MutableList<Interceptor> = mutableListOf()
internal var eventListenerFactory: EventListener.Factory = Util.eventListenerFactory(
internal var eventListenerFactory: EventListener.Factory = eventListenerFactory(
EventListener.NONE)
internal var proxySelector: ProxySelector = ProxySelector.getDefault() ?: NullProxySelector()
internal var cookieJar: CookieJar = CookieJar.NO_COOKIES
Expand Down Expand Up @@ -793,7 +794,7 @@ open class OkHttpClient internal constructor(
* @see EventListener for semantics and restrictions on listener implementations.
*/
fun eventListener(eventListener: EventListener) = apply {
this.eventListenerFactory = Util.eventListenerFactory(eventListener)
this.eventListenerFactory = eventListenerFactory(eventListener)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/java/okhttp3/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package okhttp3

import okhttp3.internal.Util
import okhttp3.internal.EMPTY_REQUEST
import okhttp3.internal.http.HttpMethod
import okhttp3.internal.toImmutableMap
import java.net.URL
Expand Down Expand Up @@ -188,7 +188,7 @@ class Request internal constructor(
open fun post(body: RequestBody) = method("POST", body)

@JvmOverloads
open fun delete(body: RequestBody? = Util.EMPTY_REQUEST) = method("DELETE", body)
open fun delete(body: RequestBody? = EMPTY_REQUEST) = method("DELETE", body)

open fun put(body: RequestBody) = method("PUT", body)

Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/java/okhttp3/RequestBody.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package okhttp3

import okhttp3.internal.Util
import okhttp3.internal.checkOffsetAndCount
import okio.BufferedSink
import okio.ByteString
import okio.source
Expand Down Expand Up @@ -135,7 +135,7 @@ abstract class RequestBody {
offset: Int = 0,
byteCount: Int = content.size
): RequestBody {
Util.checkOffsetAndCount(content.size.toLong(), offset.toLong(), byteCount.toLong())
checkOffsetAndCount(content.size.toLong(), offset.toLong(), byteCount.toLong())
return object : RequestBody() {
override fun contentType() = contentType

Expand Down
6 changes: 3 additions & 3 deletions okhttp/src/main/java/okhttp3/ResponseBody.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package okhttp3

import okhttp3.internal.Util
import okhttp3.internal.bomAwareCharset
import okhttp3.internal.closeQuietly
import okio.Buffer
import okio.BufferedSource
Expand Down Expand Up @@ -168,7 +168,7 @@ abstract class ResponseBody : Closeable {
*/
@Throws(IOException::class)
fun string(): String = source().use { source ->
source.readString(charset = Util.bomAwareCharset(source, charset()))
source.readString(charset = bomAwareCharset(source, charset()))
}

private fun charset() = contentType()?.charset(UTF_8) ?: UTF_8
Expand All @@ -189,7 +189,7 @@ abstract class ResponseBody : Closeable {

val finalDelegate = delegate ?: InputStreamReader(
source.inputStream(),
Util.bomAwareCharset(source, charset)).also {
bomAwareCharset(source, charset)).also {
delegate = it
}
return finalDelegate.read(cbuf, off, len)
Expand Down
Loading

0 comments on commit 0718352

Please sign in to comment.