Skip to content

Commit

Permalink
Well actually
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 17, 2024
1 parent fe6b5c9 commit 3e6bff7
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 116 deletions.
91 changes: 46 additions & 45 deletions okio/src/jvmMain/kotlin/okio/Buffer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ actual class Buffer : BufferedSource, BufferedSink, Cloneable, ByteChannel {

actual override fun emit() = this // Nowhere to emit to!

override fun exhausted() = size == 0L
actual override fun exhausted() = size == 0L

@Throws(EOFException::class)
override fun require(byteCount: Long) {
actual override fun require(byteCount: Long) {
if (size < byteCount) throw EOFException()
}

override fun request(byteCount: Long) = size >= byteCount
actual override fun request(byteCount: Long) = size >= byteCount

override fun peek(): BufferedSource {
actual override fun peek(): BufferedSource {
return PeekSource(this).buffer()
}

Expand Down Expand Up @@ -252,54 +252,54 @@ actual class Buffer : BufferedSource, BufferedSink, Cloneable, ByteChannel {
actual fun completeSegmentByteCount(): Long = commonCompleteSegmentByteCount()

@Throws(EOFException::class)
override fun readByte(): Byte = commonReadByte()
actual override fun readByte(): Byte = commonReadByte()

@JvmName("getByte")
actual operator fun get(pos: Long): Byte = commonGet(pos)

@Throws(EOFException::class)
override fun readShort(): Short = commonReadShort()
actual override fun readShort(): Short = commonReadShort()

@Throws(EOFException::class)
override fun readInt(): Int = commonReadInt()
actual override fun readInt(): Int = commonReadInt()

@Throws(EOFException::class)
override fun readLong(): Long = commonReadLong()
actual override fun readLong(): Long = commonReadLong()

@Throws(EOFException::class)
override fun readShortLe() = readShort().reverseBytes()
actual override fun readShortLe() = readShort().reverseBytes()

@Throws(EOFException::class)
override fun readIntLe() = readInt().reverseBytes()
actual override fun readIntLe() = readInt().reverseBytes()

@Throws(EOFException::class)
override fun readLongLe() = readLong().reverseBytes()
actual override fun readLongLe() = readLong().reverseBytes()

@Throws(EOFException::class)
override fun readDecimalLong(): Long = commonReadDecimalLong()
actual override fun readDecimalLong(): Long = commonReadDecimalLong()

@Throws(EOFException::class)
override fun readHexadecimalUnsignedLong(): Long = commonReadHexadecimalUnsignedLong()
actual override fun readHexadecimalUnsignedLong(): Long = commonReadHexadecimalUnsignedLong()

override fun readByteString(): ByteString = commonReadByteString()
actual override fun readByteString(): ByteString = commonReadByteString()

@Throws(EOFException::class)
override fun readByteString(byteCount: Long) = commonReadByteString(byteCount)
actual override fun readByteString(byteCount: Long) = commonReadByteString(byteCount)

override fun select(options: Options): Int = commonSelect(options)
actual override fun select(options: Options): Int = commonSelect(options)

override fun <T : Any> select(options: TypedOptions<T>): T? = commonSelect(options)
actual override fun <T : Any> select(options: TypedOptions<T>): T? = commonSelect(options)

@Throws(EOFException::class)
override fun readFully(sink: Buffer, byteCount: Long): Unit = commonReadFully(sink, byteCount)
actual override fun readFully(sink: Buffer, byteCount: Long): Unit = commonReadFully(sink, byteCount)

@Throws(IOException::class)
override fun readAll(sink: Sink): Long = commonReadAll(sink)
actual override fun readAll(sink: Sink): Long = commonReadAll(sink)

override fun readUtf8() = readString(size, Charsets.UTF_8)
actual override fun readUtf8() = readString(size, Charsets.UTF_8)

@Throws(EOFException::class)
override fun readUtf8(byteCount: Long) = readString(byteCount, Charsets.UTF_8)
actual override fun readUtf8(byteCount: Long) = readString(byteCount, Charsets.UTF_8)

override fun readString(charset: Charset) = readString(size, charset)

Expand Down Expand Up @@ -328,28 +328,28 @@ actual class Buffer : BufferedSource, BufferedSink, Cloneable, ByteChannel {
}

@Throws(EOFException::class)
override fun readUtf8Line(): String? = commonReadUtf8Line()
actual override fun readUtf8Line(): String? = commonReadUtf8Line()

@Throws(EOFException::class)
override fun readUtf8LineStrict() = readUtf8LineStrict(Long.MAX_VALUE)
actual override fun readUtf8LineStrict() = readUtf8LineStrict(Long.MAX_VALUE)

@Throws(EOFException::class)
override fun readUtf8LineStrict(limit: Long): String = commonReadUtf8LineStrict(limit)
actual override fun readUtf8LineStrict(limit: Long): String = commonReadUtf8LineStrict(limit)

@Throws(EOFException::class)
override fun readUtf8CodePoint(): Int = commonReadUtf8CodePoint()
actual override fun readUtf8CodePoint(): Int = commonReadUtf8CodePoint()

override fun readByteArray() = commonReadByteArray()
actual override fun readByteArray() = commonReadByteArray()

@Throws(EOFException::class)
override fun readByteArray(byteCount: Long): ByteArray = commonReadByteArray(byteCount)
actual override fun readByteArray(byteCount: Long): ByteArray = commonReadByteArray(byteCount)

override fun read(sink: ByteArray) = commonRead(sink)
actual override fun read(sink: ByteArray) = commonRead(sink)

@Throws(EOFException::class)
override fun readFully(sink: ByteArray) = commonReadFully(sink)
actual override fun readFully(sink: ByteArray) = commonReadFully(sink)

override fun read(sink: ByteArray, offset: Int, byteCount: Int): Int =
actual override fun read(sink: ByteArray, offset: Int, byteCount: Int): Int =
commonRead(sink, offset, byteCount)

@Throws(IOException::class)
Expand Down Expand Up @@ -436,7 +436,7 @@ actual class Buffer : BufferedSource, BufferedSink, Cloneable, ByteChannel {
}

@Throws(IOException::class)
override fun writeAll(source: Source): Long = commonWriteAll(source)
actual override fun writeAll(source: Source): Long = commonWriteAll(source)

@Throws(IOException::class)
actual override fun write(source: Source, byteCount: Long): Buffer =
Expand Down Expand Up @@ -464,48 +464,49 @@ actual class Buffer : BufferedSource, BufferedSink, Cloneable, ByteChannel {
internal actual fun writableSegment(minimumCapacity: Int): Segment =
commonWritableSegment(minimumCapacity)

override fun write(source: Buffer, byteCount: Long): Unit = commonWrite(source, byteCount)
actual override fun write(source: Buffer, byteCount: Long): Unit = commonWrite(source, byteCount)

override fun read(sink: Buffer, byteCount: Long): Long = commonRead(sink, byteCount)
actual override fun read(sink: Buffer, byteCount: Long): Long = commonRead(sink, byteCount)

override fun indexOf(b: Byte) = indexOf(b, 0, Long.MAX_VALUE)
actual override fun indexOf(b: Byte) = indexOf(b, 0, Long.MAX_VALUE)

/**
* Returns the index of `b` in this at or beyond `fromIndex`, or -1 if this buffer does not
* contain `b` in that range.
*/
override fun indexOf(b: Byte, fromIndex: Long) = indexOf(b, fromIndex, Long.MAX_VALUE)
actual override fun indexOf(b: Byte, fromIndex: Long) = indexOf(b, fromIndex, Long.MAX_VALUE)

override fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long = commonIndexOf(b, fromIndex, toIndex)
actual override fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long =
commonIndexOf(b, fromIndex, toIndex)

@Throws(IOException::class)
override fun indexOf(bytes: ByteString): Long = indexOf(bytes, 0)
actual override fun indexOf(bytes: ByteString): Long = indexOf(bytes, 0)

@Throws(IOException::class)
override fun indexOf(bytes: ByteString, fromIndex: Long): Long = commonIndexOf(bytes, fromIndex)
actual override fun indexOf(bytes: ByteString, fromIndex: Long): Long = commonIndexOf(bytes, fromIndex)

override fun indexOfElement(targetBytes: ByteString) = indexOfElement(targetBytes, 0L)
actual override fun indexOfElement(targetBytes: ByteString) = indexOfElement(targetBytes, 0L)

override fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long =
actual override fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long =
commonIndexOfElement(targetBytes, fromIndex)

override fun rangeEquals(offset: Long, bytes: ByteString) =
actual override fun rangeEquals(offset: Long, bytes: ByteString) =
rangeEquals(offset, bytes, 0, bytes.size)

override fun rangeEquals(
actual override fun rangeEquals(
offset: Long,
bytes: ByteString,
bytesOffset: Int,
byteCount: Int,
): Boolean = commonRangeEquals(offset, bytes, bytesOffset, byteCount)

override fun flush() {}
actual override fun flush() {}

override fun isOpen() = true

override fun close() {}
actual override fun close() {}

override fun timeout() = Timeout.NONE
actual override fun timeout() = Timeout.NONE

/**
* Returns the 128-bit MD5 hash of this buffer.
Expand Down
2 changes: 1 addition & 1 deletion okio/src/jvmMain/kotlin/okio/HashingSink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ actual class HashingSink : ForwardingSink, Sink { // Need to explicitly declare
)

@Throws(IOException::class)
override fun write(source: Buffer, byteCount: Long) {
actual override fun write(source: Buffer, byteCount: Long) {
checkOffsetAndCount(source.size, 0, byteCount)

// Hash byteCount bytes from the prefix of source.
Expand Down
2 changes: 1 addition & 1 deletion okio/src/jvmMain/kotlin/okio/HashingSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ actual class HashingSource : ForwardingSource, Source { // Need to explicitly de
)

@Throws(IOException::class)
override fun read(sink: Buffer, byteCount: Long): Long {
actual override fun read(sink: Buffer, byteCount: Long): Long {
val result = super.read(sink, byteCount)

if (result != -1L) {
Expand Down
50 changes: 25 additions & 25 deletions okio/src/jvmMain/kotlin/okio/RealBufferedSink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ internal actual class RealBufferedSink actual constructor(
@JvmField actual var closed: Boolean = false

@Suppress("OVERRIDE_BY_INLINE") // Prevent internal code from calling the getter.
override val buffer: Buffer
actual override val buffer: Buffer
inline get() = bufferField

override fun buffer() = bufferField

override fun write(source: Buffer, byteCount: Long) = commonWrite(source, byteCount)
override fun write(byteString: ByteString) = commonWrite(byteString)
override fun write(byteString: ByteString, offset: Int, byteCount: Int) =
actual override fun write(source: Buffer, byteCount: Long) = commonWrite(source, byteCount)
actual override fun write(byteString: ByteString) = commonWrite(byteString)
actual override fun write(byteString: ByteString, offset: Int, byteCount: Int) =
commonWrite(byteString, offset, byteCount)
override fun writeUtf8(string: String) = commonWriteUtf8(string)
override fun writeUtf8(string: String, beginIndex: Int, endIndex: Int) =
actual override fun writeUtf8(string: String) = commonWriteUtf8(string)
actual override fun writeUtf8(string: String, beginIndex: Int, endIndex: Int) =
commonWriteUtf8(string, beginIndex, endIndex)

override fun writeUtf8CodePoint(codePoint: Int) = commonWriteUtf8CodePoint(codePoint)
actual override fun writeUtf8CodePoint(codePoint: Int) = commonWriteUtf8CodePoint(codePoint)

override fun writeString(string: String, charset: Charset): BufferedSink {
check(!closed) { "closed" }
Expand All @@ -79,8 +79,8 @@ internal actual class RealBufferedSink actual constructor(
return emitCompleteSegments()
}

override fun write(source: ByteArray) = commonWrite(source)
override fun write(source: ByteArray, offset: Int, byteCount: Int) =
actual override fun write(source: ByteArray) = commonWrite(source)
actual override fun write(source: ByteArray, offset: Int, byteCount: Int) =
commonWrite(source, offset, byteCount)

override fun write(source: ByteBuffer): Int {
Expand All @@ -90,19 +90,19 @@ internal actual class RealBufferedSink actual constructor(
return result
}

override fun writeAll(source: Source) = commonWriteAll(source)
override fun write(source: Source, byteCount: Long): BufferedSink = commonWrite(source, byteCount)
override fun writeByte(b: Int) = commonWriteByte(b)
override fun writeShort(s: Int) = commonWriteShort(s)
override fun writeShortLe(s: Int) = commonWriteShortLe(s)
override fun writeInt(i: Int) = commonWriteInt(i)
override fun writeIntLe(i: Int) = commonWriteIntLe(i)
override fun writeLong(v: Long) = commonWriteLong(v)
override fun writeLongLe(v: Long) = commonWriteLongLe(v)
override fun writeDecimalLong(v: Long) = commonWriteDecimalLong(v)
override fun writeHexadecimalUnsignedLong(v: Long) = commonWriteHexadecimalUnsignedLong(v)
override fun emitCompleteSegments() = commonEmitCompleteSegments()
override fun emit() = commonEmit()
actual override fun writeAll(source: Source) = commonWriteAll(source)
actual override fun write(source: Source, byteCount: Long): BufferedSink = commonWrite(source, byteCount)
actual override fun writeByte(b: Int) = commonWriteByte(b)
actual override fun writeShort(s: Int) = commonWriteShort(s)
actual override fun writeShortLe(s: Int) = commonWriteShortLe(s)
actual override fun writeInt(i: Int) = commonWriteInt(i)
actual override fun writeIntLe(i: Int) = commonWriteIntLe(i)
actual override fun writeLong(v: Long) = commonWriteLong(v)
actual override fun writeLongLe(v: Long) = commonWriteLongLe(v)
actual override fun writeDecimalLong(v: Long) = commonWriteDecimalLong(v)
actual override fun writeHexadecimalUnsignedLong(v: Long) = commonWriteHexadecimalUnsignedLong(v)
actual override fun emitCompleteSegments() = commonEmitCompleteSegments()
actual override fun emit() = commonEmit()

override fun outputStream(): OutputStream {
return object : OutputStream() {
Expand Down Expand Up @@ -131,11 +131,11 @@ internal actual class RealBufferedSink actual constructor(
}
}

override fun flush() = commonFlush()
actual override fun flush() = commonFlush()

override fun isOpen() = !closed

override fun close() = commonClose()
override fun timeout() = commonTimeout()
actual override fun close() = commonClose()
actual override fun timeout() = commonTimeout()
override fun toString() = commonToString()
}
Loading

0 comments on commit 3e6bff7

Please sign in to comment.