xref: /aosp_15_r20/external/okio/okio/src/commonMain/kotlin/okio/CommonPlatform.kt (revision f9742813c14b702d71392179818a9e591da8620c)
1 /*
2  * Copyright (C) 2018 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 @file:JvmName("-CommonPlatform") // A leading '-' hides this class from Java.
17 
18 package okio
19 
20 import kotlin.jvm.JvmName
21 
toUtf8Stringnull22 internal expect fun ByteArray.toUtf8String(): String
23 
24 internal expect fun String.asUtf8ToByteArray(): ByteArray
25 
26 // TODO make internal https://youtrack.jetbrains.com/issue/KT-37316
27 expect class ArrayIndexOutOfBoundsException(message: String?) : IndexOutOfBoundsException
28 
29 expect class Lock
30 
31 expect inline fun <T> Lock.withLock(action: () -> T): T
32 
33 internal expect fun newLock(): Lock
34 
35 expect open class IOException(message: String?, cause: Throwable?) : Exception {
36   constructor(message: String?)
37   constructor()
38 }
39 
40 expect class ProtocolException(message: String) : IOException
41 
42 expect open class EOFException(message: String?) : IOException {
43   constructor()
44 }
45 
46 expect class FileNotFoundException(message: String?) : IOException
47 
48 expect interface Closeable {
49   /**
50    * Closes this object and releases the resources it holds. It is an error to use an object after
51    * it has been closed. It is safe to close an object more than once.
52    */
53   @Throws(IOException::class)
closenull54   fun close()
55 }
56