Skip to content

Commit

Permalink
Updated public API KDoc with information of possible IOException thro…
Browse files Browse the repository at this point in the history
…wing (#351)
  • Loading branch information
fzhinkin authored Aug 20, 2024
1 parent ec78eea commit 046523f
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/common/src/ByteStrings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlin.math.min
* @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [byteString] indices.
* @throws IllegalArgumentException when `startIndex > endIndex`.
* @throws IllegalStateException if the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.ByteStringSamples.writeByteString
*/
Expand Down Expand Up @@ -56,6 +57,7 @@ public fun Sink.write(byteString: ByteString, startIndex: Int = 0, endIndex: Int
* Consumes all bytes from this source and wraps it into a byte string.
*
* @throws IllegalStateException if the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.ByteStringSamples.readByteString
*/
Expand All @@ -72,6 +74,7 @@ public fun Source.readByteString(): ByteString {
* @throws EOFException when the source is exhausted before reading [byteCount] bytes from it.
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws IllegalStateException if the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.ByteStringSamples.readByteString
*/
Expand All @@ -90,6 +93,7 @@ public fun Source.readByteString(byteCount: Int): ByteString {
*
* @throws IllegalArgumentException if [startIndex] is negative.
* @throws IllegalStateException if the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.ByteStringSamples.indexOfByteString
*/
Expand Down
6 changes: 5 additions & 1 deletion core/common/src/RawSink.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 JetBrains s.r.o. and respective authors and developers.
* Copyright 2017-2024 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file.
*/

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

/**
* Pushes all buffered bytes to their final destination.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*/
public fun flush()

/**
* Pushes all buffered bytes to their final destination and releases the resources held by this
* sink. It is an error to write a closed sink. It is safe to close a sink more than once.
*
* @throws IOException when some I/O error occurs.
*/
override fun close()
}
5 changes: 4 additions & 1 deletion core/common/src/RawSource.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 JetBrains s.r.o. and respective authors and developers.
* Copyright 2017-2024 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file.
*/

Expand Down Expand Up @@ -44,6 +44,7 @@ public interface RawSource : AutoCloseable {
*
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readAtMostToSink
*/
Expand All @@ -52,6 +53,8 @@ public interface RawSource : AutoCloseable {
/**
* Closes this source and releases the resources held by this source. It is an error to read a
* closed source. It is safe to close a source more than once.
*
* @throws IOException when some I/O error occurs.
*/
override fun close()
}
10 changes: 10 additions & 0 deletions core/common/src/Sink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public sealed interface Sink : RawSink {
* @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [source] array indices.
* @throws IllegalArgumentException when `startIndex > endIndex`.
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeByteArrayToSink
*/
Expand All @@ -88,6 +89,7 @@ public sealed interface Sink : RawSink {
* @param source the source to consume data from.
*
* @throws IllegalStateException when the sink or [source] is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.transferFrom
*/
Expand All @@ -104,6 +106,7 @@ public sealed interface Sink : RawSink {
*
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws IllegalStateException when the sink or [source] is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeSourceToSink
*/
Expand All @@ -115,6 +118,7 @@ public sealed interface Sink : RawSink {
* @param byte the byte to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeByte
*/
Expand All @@ -126,6 +130,7 @@ public sealed interface Sink : RawSink {
* @param short the short integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeShort
*/
Expand All @@ -137,6 +142,7 @@ public sealed interface Sink : RawSink {
* @param int the integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeInt
*/
Expand All @@ -148,6 +154,7 @@ public sealed interface Sink : RawSink {
* @param long the long integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeLong
*/
Expand All @@ -158,6 +165,7 @@ public sealed interface Sink : RawSink {
* Then the underlying sink is explicitly flushed.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.flush
*/
Expand All @@ -171,6 +179,7 @@ public sealed interface Sink : RawSink {
* Call this method before a buffered sink goes out of scope so that its data can reach its destination.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.emit
*/
Expand All @@ -189,6 +198,7 @@ public sealed interface Sink : RawSink {
* Consider using [Sink.writeToInternalBuffer] for writes into [buffered] followed by [hintEmit] call.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*/
@InternalIoApi
public fun hintEmit()
Expand Down
17 changes: 17 additions & 0 deletions core/common/src/Sinks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private val HEX_DIGIT_BYTES = ByteArray(16) {
* @param short the short integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeShortLe
*/
Expand All @@ -32,6 +33,7 @@ public fun Sink.writeShortLe(short: Short) {
* @param int the integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeIntLe
*/
Expand All @@ -45,6 +47,7 @@ public fun Sink.writeIntLe(int: Int) {
* @param long the long integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeLongLe
*/
Expand All @@ -60,6 +63,7 @@ public fun Sink.writeLongLe(long: Long) {
* @param long the long to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeDecimalLong
*/
Expand Down Expand Up @@ -141,6 +145,7 @@ public fun Sink.writeDecimalLong(long: Long) {
* @param long the long to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeHexLong
*/
Expand Down Expand Up @@ -176,6 +181,7 @@ public fun Sink.writeHexadecimalUnsignedLong(long: Long) {
* @param byte the byte to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUByte
*/
Expand All @@ -189,6 +195,7 @@ public fun Sink.writeUByte(byte: UByte) {
* @param short the unsigned short integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUShort
*/
Expand All @@ -202,6 +209,7 @@ public fun Sink.writeUShort(short: UShort) {
* @param int the unsigned integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUInt
*/
Expand All @@ -215,6 +223,7 @@ public fun Sink.writeUInt(int: UInt) {
* @param long the unsigned long integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeULong
*/
Expand All @@ -228,6 +237,7 @@ public fun Sink.writeULong(long: ULong) {
* @param short the unsigned short integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUShortLe
*/
Expand All @@ -241,6 +251,7 @@ public fun Sink.writeUShortLe(short: UShort) {
* @param int the unsigned integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeUIntLe
*/
Expand All @@ -254,6 +265,7 @@ public fun Sink.writeUIntLe(int: UInt) {
* @param long the unsigned long integer to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeULongLe
*/
Expand All @@ -276,6 +288,7 @@ public fun Sink.writeULongLe(long: ULong) {
* @param float the floating point number to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeFloat
*/
Expand All @@ -294,6 +307,7 @@ public fun Sink.writeFloat(float: Float) {
* @param double the floating point number to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeDouble
*/
Expand All @@ -316,6 +330,7 @@ public fun Sink.writeDouble(double: Double) {
* @param float the floating point number to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeFloatLe
*/
Expand All @@ -334,6 +349,7 @@ public fun Sink.writeFloatLe(float: Float) {
* @param double the floating point number to be written.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.writeDoubleLe
*/
Expand All @@ -353,6 +369,7 @@ public fun Sink.writeDoubleLe(double: Double) {
* @param lambda the callback accessing internal buffer.
*
* @throws IllegalStateException when the sink is closed.
* @throws IOException when some I/O error occurs.
*/
@DelicateIoApi
@OptIn(InternalIoApi::class, ExperimentalContracts::class)
Expand Down
11 changes: 11 additions & 0 deletions core/common/src/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public sealed interface Source : RawSource {
* The call of this method will block until there are bytes to read or the source is definitely exhausted.
*
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.exhausted
*/
Expand All @@ -94,6 +95,7 @@ public sealed interface Source : RawSource {
* @throws EOFException when the source is exhausted before the required bytes count could be read.
* @throws IllegalStateException when the source is closed.
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.require
*/
Expand All @@ -110,6 +112,7 @@ public sealed interface Source : RawSource {
*
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.request
*/
Expand All @@ -120,6 +123,7 @@ public sealed interface Source : RawSource {
*
* @throws EOFException when there are no more bytes to read.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readByte
*/
Expand All @@ -130,6 +134,7 @@ public sealed interface Source : RawSource {
*
* @throws EOFException when there are not enough data to read a short value.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readShort
*/
Expand All @@ -140,6 +145,7 @@ public sealed interface Source : RawSource {
*
* @throws EOFException when there are not enough data to read an int value.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readInt
*/
Expand All @@ -150,6 +156,7 @@ public sealed interface Source : RawSource {
*
* @throws EOFException when there are not enough data to read a long value.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readLong
*/
Expand All @@ -163,6 +170,7 @@ public sealed interface Source : RawSource {
* @throws EOFException when the source is exhausted before the requested number of bytes can be skipped.
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.skip
*/
Expand All @@ -179,6 +187,7 @@ public sealed interface Source : RawSource {
* @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [sink] array indices.
* @throws IllegalArgumentException when `startIndex > endIndex`.
* @throws IllegalStateException when the source is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readAtMostToByteArray
*/
Expand All @@ -193,6 +202,7 @@ public sealed interface Source : RawSource {
* @throws IllegalArgumentException when [byteCount] is negative.
* @throws EOFException when the requested number of bytes cannot be read.
* @throws IllegalStateException when the source or [sink] is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.readSourceToSink
*/
Expand All @@ -207,6 +217,7 @@ public sealed interface Source : RawSource {
* @param sink the sink to which data will be written from this source.
*
* @throws IllegalStateException when the source or [sink] is closed.
* @throws IOException when some I/O error occurs.
*
* @sample kotlinx.io.samples.KotlinxIoCoreCommonSamples.transferTo
*/
Expand Down
Loading

0 comments on commit 046523f

Please sign in to comment.