@@ -9,95 +9,108 @@ package aws.smithy.kotlin.runtime.io.internal
99
1010import aws.smithy.kotlin.runtime.io.*
1111
12- internal inline fun SdkBuffer.commonSkip (byteCount : Long ) = inner.skip(byteCount)
12+ /* *
13+ * Used to wrap calls to Okio, catching Okio exceptions (e.g. okio.EOFException) and throwing our own (e.g. aws.smithy.kotlin.runtime.io.EOFException).
14+ */
15+ internal inline fun <T > SdkBuffer.wrapOkio (block : SdkBuffer .() -> T ): T = try {
16+ block()
17+ } catch (e: okio.EOFException ) {
18+ throw EOFException (" Okio operation failed" , e)
19+ } catch (e: okio.IOException ) {
20+ throw IOException (" Okio operation failed" , e)
21+ }
22+
23+ internal inline fun SdkBuffer.commonSkip (byteCount : Long ) = wrapOkio { inner.skip(byteCount) }
1324
14- internal inline fun SdkBuffer.commonReadByte (): Byte = inner.readByte()
25+ internal inline fun SdkBuffer.commonReadByte (): Byte = wrapOkio { inner.readByte() }
1526
16- internal inline fun SdkBuffer.commonReadShort (): Short = inner.readShort()
27+ internal inline fun SdkBuffer.commonReadShort (): Short = wrapOkio { inner.readShort() }
1728
18- internal inline fun SdkBuffer.commonReadShortLe (): Short = inner.readShortLe()
29+ internal inline fun SdkBuffer.commonReadShortLe (): Short = wrapOkio { inner.readShortLe() }
1930
20- internal inline fun SdkBuffer.commonReadLong (): Long = inner.readLong()
31+ internal inline fun SdkBuffer.commonReadLong (): Long = wrapOkio { inner.readLong() }
2132
22- internal inline fun SdkBuffer.commonReadLongLe (): Long = inner.readLongLe()
33+ internal inline fun SdkBuffer.commonReadLongLe (): Long = wrapOkio { inner.readLongLe() }
2334
24- internal inline fun SdkBuffer.commonReadInt (): Int = inner.readInt()
35+ internal inline fun SdkBuffer.commonReadInt (): Int = wrapOkio { inner.readInt() }
2536
26- internal inline fun SdkBuffer.commonReadIntLe (): Int = inner.readIntLe()
37+ internal inline fun SdkBuffer.commonReadIntLe (): Int = wrapOkio { inner.readIntLe() }
2738
28- internal inline fun SdkBuffer.commonReadAll (sink : SdkSink ): Long =
29- inner.readAll(sink.toOkio())
39+ internal inline fun SdkBuffer.commonReadAll (sink : SdkSink ): Long = wrapOkio { inner.readAll(sink.toOkio()) }
3040
3141internal inline fun SdkBuffer.commonRead (sink : ByteArray , offset : Int , limit : Int ): Int =
32- inner.read(sink, offset, limit)
42+ wrapOkio { inner.read(sink, offset, limit) }
3343
3444internal inline fun SdkBuffer.commonRead (sink : SdkBuffer , limit : Long ): Long =
35- inner.read(sink.inner, limit)
45+ wrapOkio { inner.read(sink.inner, limit) }
3646
37- internal inline fun SdkBuffer.commonReadByteArray (): ByteArray = inner.readByteArray()
47+ internal inline fun SdkBuffer.commonReadByteArray (): ByteArray = wrapOkio { inner.readByteArray() }
3848
39- internal inline fun SdkBuffer.commonReadByteArray (byteCount : Long ): ByteArray = inner.readByteArray(byteCount)
49+ internal inline fun SdkBuffer.commonReadByteArray (byteCount : Long ): ByteArray = wrapOkio { inner.readByteArray(byteCount) }
4050
41- internal inline fun SdkBuffer.commonReadUtf8 (): String = inner.readUtf8()
51+ internal inline fun SdkBuffer.commonReadUtf8 (): String = wrapOkio { inner.readUtf8() }
4252
43- internal inline fun SdkBuffer.commonReadUtf8 (byteCount : Long ): String = inner.readUtf8(byteCount)
53+ internal inline fun SdkBuffer.commonReadUtf8 (byteCount : Long ): String = wrapOkio { inner.readUtf8(byteCount) }
4454
45- internal inline fun SdkBuffer.commonPeek (): SdkBufferedSource = inner.peek().toSdk().buffer()
46- internal inline fun SdkBuffer.commonExhausted (): Boolean = inner.exhausted()
47- internal inline fun SdkBuffer.commonRequest (byteCount : Long ): Boolean = inner.request(byteCount)
55+ internal inline fun SdkBuffer.commonPeek (): SdkBufferedSource = wrapOkio { inner.peek().toSdk().buffer() }
4856
49- internal inline fun SdkBuffer.commonRequire (byteCount : Long ): Unit = inner.require(byteCount)
57+ internal inline fun SdkBuffer.commonExhausted (): Boolean = wrapOkio { inner.exhausted() }
58+
59+ internal inline fun SdkBuffer.commonRequest (byteCount : Long ): Boolean = wrapOkio { inner.request(byteCount) }
60+
61+ internal inline fun SdkBuffer.commonRequire (byteCount : Long ) = wrapOkio { inner.require(byteCount) }
5062
5163internal inline fun SdkBuffer.commonWrite (source : ByteArray , offset : Int , limit : Int ) {
52- inner.write(source, offset, limit)
64+ wrapOkio { inner.write(source, offset, limit) }
5365}
5466
5567internal inline fun SdkBuffer.commonWrite (source : SdkSource , byteCount : Long ) {
56- inner.write(source.toOkio(), byteCount)
68+ wrapOkio { inner.write(source.toOkio(), byteCount) }
5769}
70+
5871internal inline fun SdkBuffer.commonWrite (source : SdkBuffer , byteCount : Long ) {
59- inner.write(source.toOkio(), byteCount)
72+ wrapOkio { inner.write(source.toOkio(), byteCount) }
6073}
6174
6275internal inline fun SdkBuffer.commonWriteAll (source : SdkSource ): Long =
63- inner.writeAll(source.toOkio())
76+ wrapOkio { inner.writeAll(source.toOkio()) }
6477
6578internal inline fun SdkBuffer.commonWriteUtf8 (string : String , start : Int , endExclusive : Int ) {
66- inner.writeUtf8(string, start, endExclusive)
79+ wrapOkio { inner.writeUtf8(string, start, endExclusive) }
6780}
6881
6982internal inline fun SdkBuffer.commonWriteByte (x : Byte ) {
70- inner.writeByte(x.toInt())
83+ wrapOkio { inner.writeByte(x.toInt()) }
7184}
7285
7386internal inline fun SdkBuffer.commonWriteShort (x : Short ) {
74- inner.writeShort(x.toInt())
87+ wrapOkio { inner.writeShort(x.toInt()) }
7588}
7689
7790internal inline fun SdkBuffer.commonWriteShortLe (x : Short ) {
78- inner.writeShortLe(x.toInt())
91+ wrapOkio { inner.writeShortLe(x.toInt()) }
7992}
8093
8194internal inline fun SdkBuffer.commonWriteInt (x : Int ) {
82- inner.writeInt(x)
95+ wrapOkio { inner.writeInt(x) }
8396}
8497
8598internal inline fun SdkBuffer.commonWriteIntLe (x : Int ) {
86- inner.writeIntLe(x)
99+ wrapOkio { inner.writeIntLe(x) }
87100}
88101
89102internal inline fun SdkBuffer.commonWriteLong (x : Long ) {
90- inner.writeLong(x)
103+ wrapOkio { inner.writeLong(x) }
91104}
92105
93106internal inline fun SdkBuffer.commonWriteLongLe (x : Long ) {
94- inner.writeLongLe(x)
107+ wrapOkio { inner.writeLongLe(x) }
95108}
96109
97110internal inline fun SdkBuffer.commonFlush () {
98- inner.flush()
111+ wrapOkio { inner.flush() }
99112}
100113
101114internal inline fun SdkBuffer.commonClose () {
102- inner.close()
115+ wrapOkio { inner.close() }
103116}
0 commit comments