Skip to content

Specify IOException among other exception that could be thrown by I/O function calls #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -15,6 +15,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 @@ -28,6 +29,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 @@ -41,6 +43,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 @@ -56,6 +59,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 @@ -137,6 +141,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 @@ -172,6 +177,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 @@ -185,6 +191,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 @@ -198,6 +205,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 @@ -211,6 +219,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 @@ -224,6 +233,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 @@ -237,6 +247,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 @@ -250,6 +261,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 @@ -272,6 +284,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 @@ -290,6 +303,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 @@ -312,6 +326,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 @@ -330,6 +345,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 @@ -349,6 +365,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)
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