xref: /aosp_15_r20/external/okio/okio/src/jvmMain/kotlin/okio/ForwardingTimeout.kt (revision f9742813c14b702d71392179818a9e591da8620c)
1 /*
2  * Copyright (C) 2015 Square, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package okio
17 
18 import java.io.IOException
19 import java.util.concurrent.TimeUnit
20 import java.util.concurrent.locks.Condition
21 
22 /** A [Timeout] which forwards calls to another. Useful for subclassing.  */
23 open class ForwardingTimeout(
24   @get:JvmName("delegate")
25   @set:JvmSynthetic // So .java callers get the setter that returns this.
26   var delegate: Timeout,
27 ) : Timeout() {
28 
29   // For backwards compatibility with Okio 1.x, this exists so it can return `ForwardingTimeout`.
setDelegatenull30   fun setDelegate(delegate: Timeout): ForwardingTimeout {
31     this.delegate = delegate
32     return this
33   }
34 
timeoutnull35   override fun timeout(timeout: Long, unit: TimeUnit) = delegate.timeout(timeout, unit)
36 
37   override fun timeoutNanos() = delegate.timeoutNanos()
38 
39   override fun hasDeadline() = delegate.hasDeadline()
40 
41   override fun deadlineNanoTime() = delegate.deadlineNanoTime()
42 
43   override fun deadlineNanoTime(deadlineNanoTime: Long) = delegate.deadlineNanoTime(
44     deadlineNanoTime,
45   )
46 
47   override fun clearTimeout() = delegate.clearTimeout()
48 
49   override fun clearDeadline() = delegate.clearDeadline()
50 
51   @Throws(IOException::class)
52   override fun throwIfReached() = delegate.throwIfReached()
53 
54   override fun cancel() = delegate.cancel()
55 
56   override fun awaitSignal(condition: Condition) = delegate.awaitSignal(condition)
57 
58   override fun waitUntilNotified(monitor: Any) = delegate.waitUntilNotified(monitor)
59 }
60