Repository: square/okhttp
File: okhttp/src/commonJvmAndroid/kotlin/okhttp3/RequestBody.kt (Kotlin)

Code before:
  open fun isDuplex(): Boolean = false

  /**
   * Returns true if this body expects at most one call to [writeTo] and can be transmitted
   * at most once. This is typically used when writing the request body is destructive and it is not
   * possible to recreate the request body after it has been sent.
   *
   * This method returns false unless it is overridden by a subclass.
   *
   * By default OkHttp will attempt to retransmit request bodies when the original request fails
   * due to any of:
   *
   *  * A stale connection. The request was made on a reused connection and that reused connection
   *    has since been closed by the server.
   *  * A client timeout (HTTP 408).
   *  * A authorization challenge (HTTP 401 and 407) that is satisfied by the [Authenticator].
   *  * A retryable server failure (HTTP 503 with a `Retry-After: 0` response header).
   *  * A misdirected request (HTTP 421) on a coalesced connection.
   */
  open fun isOneShot(): Boolean = false

  /**
   * Returns the SHA-256 hash of this [RequestBody]
   */
  fun sha256(): ByteString {
    val hashingSink = HashingSink.sha256(blackholeSink())
    hashingSink.buffer().use {
      this.writeTo(it)
    }
    return hashingSink.hash
  }

  companion object {
    /** Empty request body with no content-type. */
    @JvmField
    val EMPTY: RequestBody = ByteString.EMPTY.toRequestBody()

    /**
     * Returns a new request body that transmits this string. If [contentType] is non-null and lacks
     * a charset, this will use UTF-8.
     */
    @JvmStatic
    @JvmName("create")
    fun String.toRequestBody(contentType: MediaType? = null): RequestBody {
      val (charset, finalContentType) = contentType.chooseCharset()
      val bytes = toByteArray(charset)
      return bytes.toRequestBody(finalContentType, 0, bytes.size)
    }

    @JvmStatic
    @JvmName("create")

Review comment (performance):
Should this have a verb, like "compute", given that it's doing something expensive (from an I/O perspective)?

Code after:
  open fun isDuplex(): Boolean = false

  /**
   * Returns true if this body expects at most one call to [writeTo] and can be transmitted
   * at most once. This is typically used when writing the request body is destructive and it is not
   * possible to recreate the request body after it has been sent.
   *
   * This method returns false unless it is overridden by a subclass.
   *
   * By default OkHttp will attempt to retransmit request bodies when the original request fails
   * due to any of:
   *
   *  * A stale connection. The request was made on a reused connection and that reused connection
   *    has since been closed by the server.
   *  * A client timeout (HTTP 408).
   *  * A authorization challenge (HTTP 401 and 407) that is satisfied by the [Authenticator].
   *  * A retryable server failure (HTTP 503 with a `Retry-After: 0` response header).
   *  * A misdirected request (HTTP 421) on a coalesced connection.
   */
  open fun isOneShot(): Boolean = false

  /**
   * Returns the SHA-256 hash of this [RequestBody]
   */
  @Throws(IOException::class)
  fun sha256(): ByteString {
    val hashingSink = HashingSink.sha256(blackholeSink())
    hashingSink.buffer().use {
      this.writeTo(it)
    }
    return hashingSink.hash
  }

  companion object {
    /** Empty request body with no content-type. */
    @JvmField
    val EMPTY: RequestBody = ByteString.EMPTY.toRequestBody()

    /**
     * Returns a new request body that transmits this string. If [contentType] is non-null and lacks
     * a charset, this will use UTF-8.
     */
    @JvmStatic
    @JvmName("create")
    fun String.toRequestBody(contentType: MediaType? = null): RequestBody {
      val (charset, finalContentType) = contentType.chooseCharset()
      val bytes = toByteArray(charset)
      return bytes.toRequestBody(finalContentType, 0, bytes.size)
    }

    @JvmStatic