Skip to content

Commit 046523f

Browse files
authored
Updated public API KDoc with information of possible IOException throwing (#351)
1 parent ec78eea commit 046523f

File tree

10 files changed

+85
-2
lines changed

10 files changed

+85
-2
lines changed

core/common/src/ByteStrings.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import kotlin.math.min
2121
* @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [byteString] indices.
2222
* @throws IllegalArgumentException when `startIndex > endIndex`.
2323
* @throws IllegalStateException if the sink is closed.
24+
* @throws IOException when some I/O error occurs.
2425
*
2526
* @sample kotlinx.io.samples.ByteStringSamples.writeByteString
2627
*/
@@ -56,6 +57,7 @@ public fun Sink.write(byteString: ByteString, startIndex: Int = 0, endIndex: Int
5657
* Consumes all bytes from this source and wraps it into a byte string.
5758
*
5859
* @throws IllegalStateException if the source is closed.
60+
* @throws IOException when some I/O error occurs.
5961
*
6062
* @sample kotlinx.io.samples.ByteStringSamples.readByteString
6163
*/
@@ -72,6 +74,7 @@ public fun Source.readByteString(): ByteString {
7274
* @throws EOFException when the source is exhausted before reading [byteCount] bytes from it.
7375
* @throws IllegalArgumentException when [byteCount] is negative.
7476
* @throws IllegalStateException if the source is closed.
77+
* @throws IOException when some I/O error occurs.
7578
*
7679
* @sample kotlinx.io.samples.ByteStringSamples.readByteString
7780
*/
@@ -90,6 +93,7 @@ public fun Source.readByteString(byteCount: Int): ByteString {
9093
*
9194
* @throws IllegalArgumentException if [startIndex] is negative.
9295
* @throws IllegalStateException if the source is closed.
96+
* @throws IOException when some I/O error occurs.
9397
*
9498
* @sample kotlinx.io.samples.ByteStringSamples.indexOfByteString
9599
*/

core/common/src/RawSink.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2023 JetBrains s.r.o. and respective authors and developers.
2+
* Copyright 2017-2024 JetBrains s.r.o. and respective authors and developers.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file.
44
*/
55

@@ -43,19 +43,23 @@ public expect interface RawSink : AutoCloseable {
4343
*
4444
* @throws IllegalArgumentException when the [source]'s size is below [byteCount] or [byteCount] is negative.
4545
* @throws IllegalStateException when the sink is closed.
46+
* @throws IOException when some I/O error occurs.
4647
*/
4748
public fun write(source: Buffer, byteCount: Long)
4849

4950
/**
5051
* Pushes all buffered bytes to their final destination.
5152
*
5253
* @throws IllegalStateException when the sink is closed.
54+
* @throws IOException when some I/O error occurs.
5355
*/
5456
public fun flush()
5557

5658
/**
5759
* Pushes all buffered bytes to their final destination and releases the resources held by this
5860
* sink. It is an error to write a closed sink. It is safe to close a sink more than once.
61+
*
62+
* @throws IOException when some I/O error occurs.
5963
*/
6064
override fun close()
6165
}

core/common/src/RawSource.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2023 JetBrains s.r.o. and respective authors and developers.
2+
* Copyright 2017-2024 JetBrains s.r.o. and respective authors and developers.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file.
44
*/
55

@@ -44,6 +44,7 @@ public interface RawSource : AutoCloseable {
4444
*
4545
* @throws IllegalArgumentException when [byteCount] is negative.
4646
* @throws IllegalStateException when the source is closed.
47+
* @throws IOException when some I/O error occurs.
4748
*
4849
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readAtMostToSink
4950
*/
@@ -52,6 +53,8 @@ public interface RawSource : AutoCloseable {
5253
/**
5354
* Closes this source and releases the resources held by this source. It is an error to read a
5455
* closed source. It is safe to close a source more than once.
56+
*
57+
* @throws IOException when some I/O error occurs.
5558
*/
5659
override fun close()
5760
}

core/common/src/Sink.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public sealed interface Sink : RawSink {
7676
* @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [source] array indices.
7777
* @throws IllegalArgumentException when `startIndex > endIndex`.
7878
* @throws IllegalStateException when the sink is closed.
79+
* @throws IOException when some I/O error occurs.
7980
*
8081
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeByteArrayToSink
8182
*/
@@ -88,6 +89,7 @@ public sealed interface Sink : RawSink {
8889
* @param source the source to consume data from.
8990
*
9091
* @throws IllegalStateException when the sink or [source] is closed.
92+
* @throws IOException when some I/O error occurs.
9193
*
9294
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.transferFrom
9395
*/
@@ -104,6 +106,7 @@ public sealed interface Sink : RawSink {
104106
*
105107
* @throws IllegalArgumentException when [byteCount] is negative.
106108
* @throws IllegalStateException when the sink or [source] is closed.
109+
* @throws IOException when some I/O error occurs.
107110
*
108111
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeSourceToSink
109112
*/
@@ -115,6 +118,7 @@ public sealed interface Sink : RawSink {
115118
* @param byte the byte to be written.
116119
*
117120
* @throws IllegalStateException when the sink is closed.
121+
* @throws IOException when some I/O error occurs.
118122
*
119123
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeByte
120124
*/
@@ -126,6 +130,7 @@ public sealed interface Sink : RawSink {
126130
* @param short the short integer to be written.
127131
*
128132
* @throws IllegalStateException when the sink is closed.
133+
* @throws IOException when some I/O error occurs.
129134
*
130135
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeShort
131136
*/
@@ -137,6 +142,7 @@ public sealed interface Sink : RawSink {
137142
* @param int the integer to be written.
138143
*
139144
* @throws IllegalStateException when the sink is closed.
145+
* @throws IOException when some I/O error occurs.
140146
*
141147
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeInt
142148
*/
@@ -148,6 +154,7 @@ public sealed interface Sink : RawSink {
148154
* @param long the long integer to be written.
149155
*
150156
* @throws IllegalStateException when the sink is closed.
157+
* @throws IOException when some I/O error occurs.
151158
*
152159
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeLong
153160
*/
@@ -158,6 +165,7 @@ public sealed interface Sink : RawSink {
158165
* Then the underlying sink is explicitly flushed.
159166
*
160167
* @throws IllegalStateException when the sink is closed.
168+
* @throws IOException when some I/O error occurs.
161169
*
162170
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.flush
163171
*/
@@ -171,6 +179,7 @@ public sealed interface Sink : RawSink {
171179
* Call this method before a buffered sink goes out of scope so that its data can reach its destination.
172180
*
173181
* @throws IllegalStateException when the sink is closed.
182+
* @throws IOException when some I/O error occurs.
174183
*
175184
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.emit
176185
*/
@@ -189,6 +198,7 @@ public sealed interface Sink : RawSink {
189198
* Consider using [Sink.writeToInternalBuffer] for writes into [buffered] followed by [hintEmit] call.
190199
*
191200
* @throws IllegalStateException when the sink is closed.
201+
* @throws IOException when some I/O error occurs.
192202
*/
193203
@InternalIoApi
194204
public fun hintEmit()

core/common/src/Sinks.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ private val HEX_DIGIT_BYTES = ByteArray(16) {
1919
* @param short the short integer to be written.
2020
*
2121
* @throws IllegalStateException when the sink is closed.
22+
* @throws IOException when some I/O error occurs.
2223
*
2324
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeShortLe
2425
*/
@@ -32,6 +33,7 @@ public fun Sink.writeShortLe(short: Short) {
3233
* @param int the integer to be written.
3334
*
3435
* @throws IllegalStateException when the sink is closed.
36+
* @throws IOException when some I/O error occurs.
3537
*
3638
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeIntLe
3739
*/
@@ -45,6 +47,7 @@ public fun Sink.writeIntLe(int: Int) {
4547
* @param long the long integer to be written.
4648
*
4749
* @throws IllegalStateException when the sink is closed.
50+
* @throws IOException when some I/O error occurs.
4851
*
4952
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeLongLe
5053
*/
@@ -60,6 +63,7 @@ public fun Sink.writeLongLe(long: Long) {
6063
* @param long the long to be written.
6164
*
6265
* @throws IllegalStateException when the sink is closed.
66+
* @throws IOException when some I/O error occurs.
6367
*
6468
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeDecimalLong
6569
*/
@@ -141,6 +145,7 @@ public fun Sink.writeDecimalLong(long: Long) {
141145
* @param long the long to be written.
142146
*
143147
* @throws IllegalStateException when the sink is closed.
148+
* @throws IOException when some I/O error occurs.
144149
*
145150
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeHexLong
146151
*/
@@ -176,6 +181,7 @@ public fun Sink.writeHexadecimalUnsignedLong(long: Long) {
176181
* @param byte the byte to be written.
177182
*
178183
* @throws IllegalStateException when the sink is closed.
184+
* @throws IOException when some I/O error occurs.
179185
*
180186
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUByte
181187
*/
@@ -189,6 +195,7 @@ public fun Sink.writeUByte(byte: UByte) {
189195
* @param short the unsigned short integer to be written.
190196
*
191197
* @throws IllegalStateException when the sink is closed.
198+
* @throws IOException when some I/O error occurs.
192199
*
193200
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUShort
194201
*/
@@ -202,6 +209,7 @@ public fun Sink.writeUShort(short: UShort) {
202209
* @param int the unsigned integer to be written.
203210
*
204211
* @throws IllegalStateException when the sink is closed.
212+
* @throws IOException when some I/O error occurs.
205213
*
206214
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUInt
207215
*/
@@ -215,6 +223,7 @@ public fun Sink.writeUInt(int: UInt) {
215223
* @param long the unsigned long integer to be written.
216224
*
217225
* @throws IllegalStateException when the sink is closed.
226+
* @throws IOException when some I/O error occurs.
218227
*
219228
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeULong
220229
*/
@@ -228,6 +237,7 @@ public fun Sink.writeULong(long: ULong) {
228237
* @param short the unsigned short integer to be written.
229238
*
230239
* @throws IllegalStateException when the sink is closed.
240+
* @throws IOException when some I/O error occurs.
231241
*
232242
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUShortLe
233243
*/
@@ -241,6 +251,7 @@ public fun Sink.writeUShortLe(short: UShort) {
241251
* @param int the unsigned integer to be written.
242252
*
243253
* @throws IllegalStateException when the sink is closed.
254+
* @throws IOException when some I/O error occurs.
244255
*
245256
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUIntLe
246257
*/
@@ -254,6 +265,7 @@ public fun Sink.writeUIntLe(int: UInt) {
254265
* @param long the unsigned long integer to be written.
255266
*
256267
* @throws IllegalStateException when the sink is closed.
268+
* @throws IOException when some I/O error occurs.
257269
*
258270
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeULongLe
259271
*/
@@ -276,6 +288,7 @@ public fun Sink.writeULongLe(long: ULong) {
276288
* @param float the floating point number to be written.
277289
*
278290
* @throws IllegalStateException when the sink is closed.
291+
* @throws IOException when some I/O error occurs.
279292
*
280293
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeFloat
281294
*/
@@ -294,6 +307,7 @@ public fun Sink.writeFloat(float: Float) {
294307
* @param double the floating point number to be written.
295308
*
296309
* @throws IllegalStateException when the sink is closed.
310+
* @throws IOException when some I/O error occurs.
297311
*
298312
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeDouble
299313
*/
@@ -316,6 +330,7 @@ public fun Sink.writeDouble(double: Double) {
316330
* @param float the floating point number to be written.
317331
*
318332
* @throws IllegalStateException when the sink is closed.
333+
* @throws IOException when some I/O error occurs.
319334
*
320335
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeFloatLe
321336
*/
@@ -334,6 +349,7 @@ public fun Sink.writeFloatLe(float: Float) {
334349
* @param double the floating point number to be written.
335350
*
336351
* @throws IllegalStateException when the sink is closed.
352+
* @throws IOException when some I/O error occurs.
337353
*
338354
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeDoubleLe
339355
*/
@@ -353,6 +369,7 @@ public fun Sink.writeDoubleLe(double: Double) {
353369
* @param lambda the callback accessing internal buffer.
354370
*
355371
* @throws IllegalStateException when the sink is closed.
372+
* @throws IOException when some I/O error occurs.
356373
*/
357374
@DelicateIoApi
358375
@OptIn(InternalIoApi::class, ExperimentalContracts::class)

core/common/src/Source.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public sealed interface Source : RawSource {
7777
* The call of this method will block until there are bytes to read or the source is definitely exhausted.
7878
*
7979
* @throws IllegalStateException when the source is closed.
80+
* @throws IOException when some I/O error occurs.
8081
*
8182
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.exhausted
8283
*/
@@ -94,6 +95,7 @@ public sealed interface Source : RawSource {
9495
* @throws EOFException when the source is exhausted before the required bytes count could be read.
9596
* @throws IllegalStateException when the source is closed.
9697
* @throws IllegalArgumentException when [byteCount] is negative.
98+
* @throws IOException when some I/O error occurs.
9799
*
98100
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.require
99101
*/
@@ -110,6 +112,7 @@ public sealed interface Source : RawSource {
110112
*
111113
* @throws IllegalArgumentException when [byteCount] is negative.
112114
* @throws IllegalStateException when the source is closed.
115+
* @throws IOException when some I/O error occurs.
113116
*
114117
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.request
115118
*/
@@ -120,6 +123,7 @@ public sealed interface Source : RawSource {
120123
*
121124
* @throws EOFException when there are no more bytes to read.
122125
* @throws IllegalStateException when the source is closed.
126+
* @throws IOException when some I/O error occurs.
123127
*
124128
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readByte
125129
*/
@@ -130,6 +134,7 @@ public sealed interface Source : RawSource {
130134
*
131135
* @throws EOFException when there are not enough data to read a short value.
132136
* @throws IllegalStateException when the source is closed.
137+
* @throws IOException when some I/O error occurs.
133138
*
134139
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readShort
135140
*/
@@ -140,6 +145,7 @@ public sealed interface Source : RawSource {
140145
*
141146
* @throws EOFException when there are not enough data to read an int value.
142147
* @throws IllegalStateException when the source is closed.
148+
* @throws IOException when some I/O error occurs.
143149
*
144150
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readInt
145151
*/
@@ -150,6 +156,7 @@ public sealed interface Source : RawSource {
150156
*
151157
* @throws EOFException when there are not enough data to read a long value.
152158
* @throws IllegalStateException when the source is closed.
159+
* @throws IOException when some I/O error occurs.
153160
*
154161
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readLong
155162
*/
@@ -163,6 +170,7 @@ public sealed interface Source : RawSource {
163170
* @throws EOFException when the source is exhausted before the requested number of bytes can be skipped.
164171
* @throws IllegalArgumentException when [byteCount] is negative.
165172
* @throws IllegalStateException when the source is closed.
173+
* @throws IOException when some I/O error occurs.
166174
*
167175
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.skip
168176
*/
@@ -179,6 +187,7 @@ public sealed interface Source : RawSource {
179187
* @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [sink] array indices.
180188
* @throws IllegalArgumentException when `startIndex > endIndex`.
181189
* @throws IllegalStateException when the source is closed.
190+
* @throws IOException when some I/O error occurs.
182191
*
183192
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readAtMostToByteArray
184193
*/
@@ -193,6 +202,7 @@ public sealed interface Source : RawSource {
193202
* @throws IllegalArgumentException when [byteCount] is negative.
194203
* @throws EOFException when the requested number of bytes cannot be read.
195204
* @throws IllegalStateException when the source or [sink] is closed.
205+
* @throws IOException when some I/O error occurs.
196206
*
197207
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readSourceToSink
198208
*/
@@ -207,6 +217,7 @@ public sealed interface Source : RawSource {
207217
* @param sink the sink to which data will be written from this source.
208218
*
209219
* @throws IllegalStateException when the source or [sink] is closed.
220+
* @throws IOException when some I/O error occurs.
210221
*
211222
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.transferTo
212223
*/

0 commit comments

Comments
 (0)