Skip to content

Commit

Permalink
Multiplat read/write ByteString, ByteArray.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrjr committed Apr 8, 2019
1 parent 41e9e30 commit 5a0b542
Show file tree
Hide file tree
Showing 24 changed files with 678 additions and 363 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ reports
*.ipr
*.iws
classes
local.properties

obj

Expand Down
4 changes: 4 additions & 0 deletions okio/js/src/main/kotlin/okio/-Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ actual open class ArrayIndexOutOfBoundsException actual constructor(
) : IndexOutOfBoundsException(message)

internal actual inline fun <R> synchronized(lock: Any, block: () -> R): R = block()

actual open class IOException actual constructor(message: String?) : Exception(message)

actual open class EOFException actual constructor(message: String?) : IOException(message)
157 changes: 94 additions & 63 deletions okio/js/src/main/kotlin/okio/Buffer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,141 +15,172 @@
*/
package okio

import okio.internal.commonCopyTo
import okio.internal.commonGet
import okio.internal.commonRead
import okio.internal.commonReadByte
import okio.internal.commonReadByteArray
import okio.internal.commonReadByteString
import okio.internal.commonReadFully
import okio.internal.commonWritableSegment
import okio.internal.commonWrite

actual class Buffer : BufferedSource, BufferedSink {
internal actual var head: Segment? = null

actual var size: Long = 0L
internal set

actual override val buffer: Buffer get() = this

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

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

override fun exhausted(): Boolean = throw UnsupportedOperationException()
override fun exhausted(): Boolean = TODO()

override fun require(byteCount: Long) {
throw UnsupportedOperationException()
TODO()
}

override fun request(byteCount: Long): Boolean = throw UnsupportedOperationException()
override fun request(byteCount: Long): Boolean = TODO()

override fun peek(): BufferedSource = throw UnsupportedOperationException()
override fun peek(): BufferedSource = PeekSource(this).buffer()

override fun readByte(): Byte = throw UnsupportedOperationException()
actual fun copyTo(
out: Buffer,
offset: Long,
byteCount: Long
): Buffer = commonCopyTo(out, offset, byteCount)

override fun readShort(): Short = throw UnsupportedOperationException()
/**
* Overload of [copyTo] with byteCount = size - offset, work around for
* https://youtrack.jetbrains.com/issue/KT-30847
*/
actual fun copyTo(
out: Buffer,
offset: Long
): Buffer = copyTo(out, offset, size - offset)

override fun readInt(): Int = throw UnsupportedOperationException()
operator fun get(pos: Long): Byte = commonGet(pos)

override fun readLong(): Long = throw UnsupportedOperationException()
override fun readByte(): Byte = commonReadByte()

override fun readShortLe(): Short = throw UnsupportedOperationException()
override fun readShort(): Short = TODO()

override fun readIntLe(): Int = throw UnsupportedOperationException()
override fun readInt(): Int = TODO()

override fun readLongLe(): Long = throw UnsupportedOperationException()
override fun readLong(): Long = TODO()

override fun readDecimalLong(): Long = throw UnsupportedOperationException()
override fun readShortLe(): Short = TODO()

override fun readHexadecimalUnsignedLong(): Long = throw UnsupportedOperationException()
override fun readIntLe(): Int = TODO()

override fun readByteString(): ByteString = throw UnsupportedOperationException()
override fun readLongLe(): Long = TODO()

override fun readByteString(byteCount: Long): ByteString = throw UnsupportedOperationException()
override fun readDecimalLong(): Long = TODO()

override fun readFully(sink: Buffer, byteCount: Long) {
throw UnsupportedOperationException()
}
override fun readHexadecimalUnsignedLong(): Long = TODO()

override fun readAll(sink: Sink): Long = throw UnsupportedOperationException()
override fun readByteString(): ByteString = commonReadByteString()

override fun readUtf8(): String = throw UnsupportedOperationException()
override fun readByteString(byteCount: Long): ByteString = commonReadByteString(byteCount)

override fun readUtf8(byteCount: Long): String = throw UnsupportedOperationException()
override fun readFully(sink: Buffer, byteCount: Long) = TODO()

override fun readUtf8Line(): String? = throw UnsupportedOperationException()
override fun readAll(sink: Sink): Long = TODO()

override fun readUtf8LineStrict(): String = throw UnsupportedOperationException()
override fun readUtf8(): String = TODO()

override fun readUtf8LineStrict(limit: Long): String = throw UnsupportedOperationException()
override fun readUtf8(byteCount: Long): String = TODO()

override fun readUtf8CodePoint(): Int = throw UnsupportedOperationException()
override fun readUtf8Line(): String? = TODO()

override fun readByteArray(): ByteArray = throw UnsupportedOperationException()
override fun readUtf8LineStrict(): String = TODO()

override fun readByteArray(byteCount: Long): ByteArray = throw UnsupportedOperationException()
override fun readUtf8LineStrict(limit: Long): String = TODO()

override fun read(sink: ByteArray): Int = throw UnsupportedOperationException()
override fun readUtf8CodePoint(): Int = TODO()

override fun readFully(sink: ByteArray) {
throw UnsupportedOperationException()
}
override fun readByteArray(): ByteArray = commonReadByteArray()

override fun read(sink: ByteArray, offset: Int, byteCount: Int): Int = throw UnsupportedOperationException()
override fun readByteArray(byteCount: Long): ByteArray = commonReadByteArray(byteCount)

override fun skip(byteCount: Long) {
throw UnsupportedOperationException()
}
override fun read(sink: ByteArray): Int = commonRead(sink)

override fun readFully(sink: ByteArray) = commonReadFully(sink)

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

override fun skip(byteCount: Long) = TODO()

actual override fun write(byteString: ByteString): Buffer = commonWrite(byteString)

actual override fun write(byteString: ByteString): Buffer = throw UnsupportedOperationException()
internal actual fun writableSegment(minimumCapacity: Int): Segment =
commonWritableSegment(minimumCapacity)

actual override fun writeUtf8(string: String): Buffer = throw UnsupportedOperationException()
actual override fun writeUtf8(string: String): Buffer = TODO()

actual override fun writeUtf8(string: String, beginIndex: Int, endIndex: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeUtf8(string: String, beginIndex: Int, endIndex: Int): Buffer = TODO()

actual override fun writeUtf8CodePoint(codePoint: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeUtf8CodePoint(codePoint: Int): Buffer = TODO()

actual override fun write(source: ByteArray): Buffer = throw UnsupportedOperationException()
actual override fun write(source: ByteArray): Buffer = commonWrite(source)

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

override fun writeAll(source: Source): Long = throw UnsupportedOperationException()
override fun writeAll(source: Source): Long = TODO()

actual override fun write(source: Source, byteCount: Long): Buffer = throw UnsupportedOperationException()
actual override fun write(source: Source, byteCount: Long): Buffer = TODO()

actual override fun writeByte(b: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeByte(b: Int): Buffer = TODO()

actual override fun writeShort(s: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeShort(s: Int): Buffer = TODO()

actual override fun writeShortLe(s: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeShortLe(s: Int): Buffer = TODO()

actual override fun writeInt(i: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeInt(i: Int): Buffer = TODO()

actual override fun writeIntLe(i: Int): Buffer = throw UnsupportedOperationException()
actual override fun writeIntLe(i: Int): Buffer = TODO()

actual override fun writeLong(v: Long): Buffer = throw UnsupportedOperationException()
actual override fun writeLong(v: Long): Buffer = TODO()

actual override fun writeLongLe(v: Long): Buffer = throw UnsupportedOperationException()
actual override fun writeLongLe(v: Long): Buffer = TODO()

actual override fun writeDecimalLong(v: Long): Buffer = throw UnsupportedOperationException()
actual override fun writeDecimalLong(v: Long): Buffer = TODO()

actual override fun writeHexadecimalUnsignedLong(v: Long): Buffer = throw UnsupportedOperationException()
actual override fun writeHexadecimalUnsignedLong(v: Long): Buffer = TODO()

override fun write(source: Buffer, byteCount: Long) {
throw UnsupportedOperationException()
TODO()
}

override fun read(sink: Buffer, byteCount: Long): Long = throw UnsupportedOperationException()
override fun read(sink: Buffer, byteCount: Long): Long = TODO()

override fun indexOf(b: Byte): Long = throw UnsupportedOperationException()
override fun indexOf(b: Byte): Long = TODO()

override fun indexOf(b: Byte, fromIndex: Long): Long = throw UnsupportedOperationException()
override fun indexOf(b: Byte, fromIndex: Long): Long = TODO()

override fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long = throw UnsupportedOperationException()
override fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long = TODO()

override fun indexOf(bytes: ByteString): Long = throw UnsupportedOperationException()
override fun indexOf(bytes: ByteString): Long = TODO()

override fun indexOf(bytes: ByteString, fromIndex: Long): Long = throw UnsupportedOperationException()
override fun indexOf(bytes: ByteString, fromIndex: Long): Long = TODO()

override fun indexOfElement(targetBytes: ByteString): Long = throw UnsupportedOperationException()
override fun indexOfElement(targetBytes: ByteString): Long = TODO()

override fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long = throw UnsupportedOperationException()
override fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long = TODO()

override fun rangeEquals(offset: Long, bytes: ByteString): Boolean = throw UnsupportedOperationException()
override fun rangeEquals(offset: Long, bytes: ByteString): Boolean = TODO()

override fun rangeEquals(
offset: Long,
bytes: ByteString,
bytesOffset: Int,
byteCount: Int
): Boolean = throw UnsupportedOperationException()
): Boolean = TODO()

override fun flush() {
}
Expand Down
3 changes: 3 additions & 0 deletions okio/js/src/main/kotlin/okio/ByteString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import okio.internal.commonToByteArray
import okio.internal.commonToByteString
import okio.internal.commonToString
import okio.internal.commonUtf8
import okio.internal.commonWrite

/**
* An immutable sequence of bytes.
Expand Down Expand Up @@ -111,6 +112,8 @@ internal actual constructor(
/** Returns the bytes of this string without a defensive copy. Do not mutate! */
internal actual open fun internalArray() = commonInternalArray()

internal actual open fun write(buffer: Buffer) = commonWrite(buffer)

/**
* Returns true if the bytes of this in `[offset..offset+byteCount)` equal the bytes of `other` in
* `[otherOffset..otherOffset+byteCount)`. Returns false if either range is out of bounds.
Expand Down
22 changes: 22 additions & 0 deletions okio/js/src/main/kotlin/okio/Okio.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2019 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okio

actual fun Source.buffer(): BufferedSource = TODO()

actual fun Sink.buffer(): BufferedSink = TODO()

actual fun blackholeSink(): Sink = TODO()
16 changes: 16 additions & 0 deletions okio/jvm/japicmp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2019 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import me.champeau.gradle.japicmp.JapicmpTask

apply plugin: 'java-library'
Expand Down Expand Up @@ -28,6 +43,7 @@ task japicmp(type: JapicmpTask, dependsOn: 'jar') {
'okio.RealBufferedSink', // Internal.
'okio.RealBufferedSource', // Internal.
'okio.SegmentedByteString', // Internal.
'okio.SegmentPool', // Internal.
'okio.Util', // Internal.
]
methodExcludes = [
Expand Down
4 changes: 4 additions & 0 deletions okio/jvm/src/main/java/okio/-Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ actual typealias ArrayIndexOutOfBoundsException = java.lang.ArrayIndexOutOfBound
internal actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
return kotlin.synchronized(lock, block)
}

actual typealias IOException = java.io.IOException

actual typealias EOFException = java.io.EOFException
Loading

0 comments on commit 5a0b542

Please sign in to comment.