xref: /aosp_15_r20/external/okio/okio/src/jvmMain/kotlin/okio/ForwardingSink.kt (revision f9742813c14b702d71392179818a9e591da8620c)
1 /*
2  * Copyright (C) 2014 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 
20 /** A [Sink] which forwards calls to another. Useful for subclassing. */
21 abstract class ForwardingSink(
22   /** [Sink] to which this instance is delegating. */
23   @get:JvmName("delegate")
24   val delegate: Sink,
25 ) : Sink {
26   // TODO 'Sink by delegate' once https://youtrack.jetbrains.com/issue/KT-23935 is fixed.
27 
28   @Throws(IOException::class)
writenull29   override fun write(source: Buffer, byteCount: Long) = delegate.write(source, byteCount)
30 
31   @Throws(IOException::class)
32   override fun flush() = delegate.flush()
33 
34   override fun timeout() = delegate.timeout()
35 
36   @Throws(IOException::class)
37   override fun close() = delegate.close()
38 
39   override fun toString() = "${javaClass.simpleName}($delegate)"
40 
41   @JvmName("-deprecated_delegate")
42   @Deprecated(
43     message = "moved to val",
44     replaceWith = ReplaceWith(expression = "delegate"),
45     level = DeprecationLevel.ERROR,
46   )
47   fun delegate() = delegate
48 }
49