From eb0b918cd1155e5718ab613c511311774137d21d Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 26 Feb 2024 11:07:46 -0500 Subject: [PATCH] Tag the language in code samples (#1445) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Tag the language in code samples * Update okio-nodefilesystem/src/main/kotlin/okio/FsJs.kt Co-authored-by: Benoît Quenaudon --------- Co-authored-by: Benoît Quenaudon --- .../src/main/kotlin/okio/FsJs.kt | 2 +- okio/src/commonMain/kotlin/okio/Buffer.kt | 14 ++--- .../commonMain/kotlin/okio/BufferedSink.kt | 39 ++++++++----- .../commonMain/kotlin/okio/BufferedSource.kt | 55 ++++++++++++------- .../kotlin/okio/ForwardingFileSystem.kt | 8 +-- .../src/commonMain/kotlin/okio/HashingSink.kt | 3 +- .../commonMain/kotlin/okio/HashingSource.kt | 3 +- okio/src/jvmMain/kotlin/okio/HashingSink.kt | 3 +- okio/src/jvmMain/kotlin/okio/HashingSource.kt | 3 +- okio/src/jvmMain/kotlin/okio/Timeout.kt | 6 +- 10 files changed, 86 insertions(+), 50 deletions(-) diff --git a/okio-nodefilesystem/src/main/kotlin/okio/FsJs.kt b/okio-nodefilesystem/src/main/kotlin/okio/FsJs.kt index 2a308f0622..223485a634 100644 --- a/okio-nodefilesystem/src/main/kotlin/okio/FsJs.kt +++ b/okio-nodefilesystem/src/main/kotlin/okio/FsJs.kt @@ -50,7 +50,7 @@ * To declare new external APIs, run Dukat to generate a full set of Node stubs. The easiest way to * do this is to add an NPM dependency on `@types/node` in `jsMain`, like this: * - * ``` + * ```kotlin * jsMain { * ... * dependencies { diff --git a/okio/src/commonMain/kotlin/okio/Buffer.kt b/okio/src/commonMain/kotlin/okio/Buffer.kt index 009ed233e2..7ebb3a7c8d 100644 --- a/okio/src/commonMain/kotlin/okio/Buffer.kt +++ b/okio/src/commonMain/kotlin/okio/Buffer.kt @@ -177,7 +177,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * * New buffers are empty and have no segments: * - * ``` + * ```kotlin * val buffer = Buffer() * ``` * @@ -185,7 +185,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * segment and writes its new data there. The lone segment has an 8 KiB byte array but only 7 * bytes of data: * - * ``` + * ```kotlin * buffer.writeUtf8("sealion") * * // [ 's', 'e', 'a', 'l', 'i', 'o', 'n', '?', '?', '?', ...] @@ -197,7 +197,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * to us. As bytes are read the data is consumed. The segment tracks this by adjusting its * internal indices. * - * ``` + * ```kotlin * buffer.readUtf8(4) // "seal" * * // [ 's', 'e', 'a', 'l', 'i', 'o', 'n', '?', '?', '?', ...] @@ -210,7 +210,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * segments. Each segment has its own start and end indexes tracking where the user's data begins * and ends. * - * ``` + * ```kotlin * val xoxo = new Buffer() * xoxo.writeUtf8("xo".repeat(5_000)) * @@ -234,7 +234,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * you may see its effects. In this example, one of the "xoxo" segments above is reused in an * unrelated buffer: * - * ``` + * ```kotlin * val abc = new Buffer() * abc.writeUtf8("abc") * @@ -247,7 +247,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * share the same underlying byte array. Clones can't write to the shared byte array; instead they * allocate a new (private) segment early. * - * ``` + * ```kotlin * val nana = new Buffer() * nana.writeUtf8("na".repeat(2_500)) * nana.readUtf8(2) // "na" @@ -291,7 +291,7 @@ expect class Buffer() : BufferedSource, BufferedSink { * [use] extension function. In this example we read all of the bytes in a buffer into a byte * array: * - * ``` + * ```kotlin * val bufferBytes = ByteArray(buffer.size.toInt()) * * buffer.readUnsafe().use { cursor -> diff --git a/okio/src/commonMain/kotlin/okio/BufferedSink.kt b/okio/src/commonMain/kotlin/okio/BufferedSink.kt index 03c8230abe..4f6927abb2 100644 --- a/okio/src/commonMain/kotlin/okio/BufferedSink.kt +++ b/okio/src/commonMain/kotlin/okio/BufferedSink.kt @@ -44,7 +44,8 @@ expect sealed interface BufferedSink : Sink { /** * Encodes `string` in UTF-8 and writes it to this sink. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeUtf8("Uh uh uh!"); * buffer.writeByte(' '); @@ -58,7 +59,8 @@ expect sealed interface BufferedSink : Sink { /** * Encodes the characters at `beginIndex` up to `endIndex` from `string` in UTF-8 and writes it to * this sink. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeUtf8("I'm a hacker!\n", 6, 12); * buffer.writeByte(' '); @@ -79,7 +81,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a big-endian short to this sink using two bytes. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeShort(32767); * buffer.writeShort(15); @@ -96,7 +99,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a little-endian short to this sink using two bytes. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeShortLe(32767); * buffer.writeShortLe(15); @@ -113,7 +117,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a big-endian int to this sink using four bytes. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeInt(2147483647); * buffer.writeInt(15); @@ -134,7 +139,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a little-endian int to this sink using four bytes. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeIntLe(2147483647); * buffer.writeIntLe(15); @@ -155,7 +161,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a big-endian long to this sink using eight bytes. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeLong(9223372036854775807L); * buffer.writeLong(15); @@ -184,7 +191,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a little-endian long to this sink using eight bytes. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeLongLe(9223372036854775807L); * buffer.writeLongLe(15); @@ -213,7 +221,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a long to this sink in signed decimal form (i.e., as a string in base 10). - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeDecimalLong(8675309L); * buffer.writeByte(' '); @@ -228,7 +237,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes a long to this sink in hexadecimal form (i.e., as a string in base 16). - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeHexadecimalUnsignedLong(65535L); * buffer.writeByte(' '); @@ -245,7 +255,8 @@ expect sealed interface BufferedSink : Sink { * Writes all buffered data to the underlying sink, if one exists. Then that sink is recursively * flushed which pushes data as far as possible towards its ultimate destination. Typically that * destination is a network socket or file. - * ``` + * + * ```java * BufferedSink b0 = new Buffer(); * BufferedSink b1 = Okio.buffer(b0); * BufferedSink b2 = Okio.buffer(b1); @@ -266,7 +277,8 @@ expect sealed interface BufferedSink : Sink { /** * Writes all buffered data to the underlying sink, if one exists. Like [flush], but weaker. Call * this before this buffered sink goes out of scope so that its data can reach its destination. - * ``` + * + * ```java * BufferedSink b0 = new Buffer(); * BufferedSink b1 = Okio.buffer(b0); * BufferedSink b2 = Okio.buffer(b1); @@ -294,7 +306,8 @@ expect sealed interface BufferedSink : Sink { * this to limit the memory held in the buffer to a single segment. Typically application code * will not need to call this: it is only necessary when application code writes directly to this * [sink's buffer][buffer]. - * ``` + * + * ```java * BufferedSink b0 = new Buffer(); * BufferedSink b1 = Okio.buffer(b0); * BufferedSink b2 = Okio.buffer(b1); diff --git a/okio/src/commonMain/kotlin/okio/BufferedSource.kt b/okio/src/commonMain/kotlin/okio/BufferedSource.kt index 18d03347e3..eaddb265af 100644 --- a/okio/src/commonMain/kotlin/okio/BufferedSource.kt +++ b/okio/src/commonMain/kotlin/okio/BufferedSource.kt @@ -47,7 +47,8 @@ expect sealed interface BufferedSource : Source { /** * Removes two bytes from this source and returns a big-endian short. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeByte(0x7f) * .writeByte(0xff) @@ -66,7 +67,8 @@ expect sealed interface BufferedSource : Source { /** * Removes two bytes from this source and returns a little-endian short. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeByte(0xff) * .writeByte(0x7f) @@ -85,7 +87,8 @@ expect sealed interface BufferedSource : Source { /** * Removes four bytes from this source and returns a big-endian int. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeByte(0x7f) * .writeByte(0xff) @@ -108,7 +111,8 @@ expect sealed interface BufferedSource : Source { /** * Removes four bytes from this source and returns a little-endian int. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeByte(0xff) * .writeByte(0xff) @@ -131,7 +135,8 @@ expect sealed interface BufferedSource : Source { /** * Removes eight bytes from this source and returns a big-endian long. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeByte(0x7f) * .writeByte(0xff) @@ -162,7 +167,8 @@ expect sealed interface BufferedSource : Source { /** * Removes eight bytes from this source and returns a little-endian long. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeByte(0xff) * .writeByte(0xff) @@ -194,7 +200,8 @@ expect sealed interface BufferedSource : Source { /** * Reads a long from this source in signed decimal form (i.e., as a string in base 10 with * optional leading '-'). This will iterate until a non-digit character is found. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeUtf8("8675309 -123 00001"); * @@ -213,7 +220,8 @@ expect sealed interface BufferedSource : Source { /** * Reads a long form this source in hexadecimal form (i.e., as a string in base 16). This will * iterate until a non-hexadecimal character is found. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeUtf8("ffff CAFEBABE 10"); * @@ -248,7 +256,8 @@ expect sealed interface BufferedSource : Source { * * This can be used as an alternative to [readByteString] or even [readUtf8] if the set of * expected values is known in advance. - * ``` + * + * ```java * Options FIELDS = Options.of( * ByteString.encodeUtf8("depth="), * ByteString.encodeUtf8("height="), @@ -276,7 +285,7 @@ expect sealed interface BufferedSource : Source { * This can be used as an alternative to [readByteString] or even [readUtf8] if the set of * expected values is known in advance. * - * ``` + * ```java * TypedOptions options = TypedOptions.of( * Arrays.asList(Direction.values()), * (direction) -> ByteString.encodeUtf8(direction.name().toLowerCase(Locale.ROOT)) @@ -338,7 +347,8 @@ expect sealed interface BufferedSource : Source { /** * Removes all bytes from this, decodes them as UTF-8, and returns the string. Returns the empty * string if this source is empty. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeUtf8("Uh uh uh!") * .writeByte(' ') @@ -355,7 +365,8 @@ expect sealed interface BufferedSource : Source { /** * Removes `byteCount` bytes from this, decodes them as UTF-8, and returns the string. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeUtf8("Uh uh uh!") * .writeByte(' ') @@ -377,7 +388,8 @@ expect sealed interface BufferedSource : Source { /** * Removes and returns characters up to but not including the next line break. A line break is * either `"\n"` or `"\r\n"`; these characters are not included in the result. - * ``` + * + * ```java * Buffer buffer = new Buffer() * .writeUtf8("I'm a hacker!\n") * .writeUtf8("That's what I said: you're a nerd.\n") @@ -425,7 +437,8 @@ expect sealed interface BufferedSource : Source { * * This method is safe. No bytes are discarded if the match fails, and the caller is free to try * another match: - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeUtf8("12345\r\n"); * @@ -459,7 +472,8 @@ expect sealed interface BufferedSource : Source { * Returns the index of the first `b` in the buffer at or after `fromIndex`. This expands the * buffer as necessary until `b` is found. This reads an unbounded number of bytes into the * buffer. Returns -1 if the stream is exhausted before the requested byte is found. - * ``` + * + * ```java * Buffer buffer = new Buffer(); * buffer.writeUtf8("Don't move! He can't see us if we don't move."); * @@ -487,7 +501,8 @@ expect sealed interface BufferedSource : Source { * expands the buffer as necessary until `bytes` is found. This reads an unbounded number of * bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are * found. - * ``` + * + * ```java * ByteString MOVE = ByteString.encodeUtf8("move"); * * Buffer buffer = new Buffer(); @@ -507,7 +522,8 @@ expect sealed interface BufferedSource : Source { * the bytes in `targetBytes`. This expands the buffer as necessary until a target byte is found. * This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted * before the requested byte is found. - * ``` + * + * ```java * ByteString ANY_VOWEL = ByteString.encodeUtf8("AEOIUaeoiu"); * * Buffer buffer = new Buffer(); @@ -523,7 +539,8 @@ expect sealed interface BufferedSource : Source { * Returns true if the bytes at `offset` in this source equal `bytes`. This expands the buffer as * necessary until a byte does not match, all bytes are matched, or if the stream is exhausted * before enough bytes could determine a match. - * ``` + * + * ```java * ByteString simonSays = ByteString.encodeUtf8("Simon says:"); * * Buffer standOnOneLeg = new Buffer().writeUtf8("Simon says: Stand on one leg."); @@ -548,7 +565,7 @@ expect sealed interface BufferedSource : Source { * * For example, we can use `peek()` to lookahead and read the same data multiple times. * - * ``` + * ```kotlin * val buffer = Buffer() * buffer.writeUtf8("abcdefghi") * diff --git a/okio/src/commonMain/kotlin/okio/ForwardingFileSystem.kt b/okio/src/commonMain/kotlin/okio/ForwardingFileSystem.kt index 3548b52b18..2fe5cd4f06 100644 --- a/okio/src/commonMain/kotlin/okio/ForwardingFileSystem.kt +++ b/okio/src/commonMain/kotlin/okio/ForwardingFileSystem.kt @@ -26,7 +26,7 @@ import kotlin.jvm.JvmName * confirm that your program behaves correctly even if its file system operations fail. For example, * this subclass fails every access of files named `unlucky.txt`: * - * ``` + * ```kotlin * val faultyFileSystem = object : ForwardingFileSystem(FileSystem.SYSTEM) { * override fun onPathParameter(path: Path, functionName: String, parameterName: String): Path { * if (path.name == "unlucky.txt") throw IOException("synthetic failure!") @@ -37,7 +37,7 @@ import kotlin.jvm.JvmName * * You can fail specific operations by overriding them directly: * - * ``` + * ```kotlin * val faultyFileSystem = object : ForwardingFileSystem(FileSystem.SYSTEM) { * override fun delete(path: Path) { * throw IOException("synthetic failure!") @@ -50,7 +50,7 @@ import kotlin.jvm.JvmName * You can extend this to verify which files your program accesses. This is a testing file system * that records accesses as they happen: * - * ``` + * ```kotlin * class LoggingFileSystem : ForwardingFileSystem(FileSystem.SYSTEM) { * val log = mutableListOf() * @@ -63,7 +63,7 @@ import kotlin.jvm.JvmName * * This makes it easy for tests to assert exactly which files were accessed. * - * ``` + * ```kotlin * @Test * fun testMergeJsonReports() { * createSampleJsonReports() diff --git a/okio/src/commonMain/kotlin/okio/HashingSink.kt b/okio/src/commonMain/kotlin/okio/HashingSink.kt index d5b8f8db9f..6e241eeb8e 100644 --- a/okio/src/commonMain/kotlin/okio/HashingSink.kt +++ b/okio/src/commonMain/kotlin/okio/HashingSink.kt @@ -22,7 +22,8 @@ package okio * * In this example we use `HashingSink` with a [BufferedSink] to make writing to the * sink easier. - * ``` + * + * ```java * HashingSink hashingSink = HashingSink.sha256(s); * BufferedSink bufferedSink = Okio.buffer(hashingSink); * diff --git a/okio/src/commonMain/kotlin/okio/HashingSource.kt b/okio/src/commonMain/kotlin/okio/HashingSource.kt index 52905ea76e..9301732d72 100644 --- a/okio/src/commonMain/kotlin/okio/HashingSource.kt +++ b/okio/src/commonMain/kotlin/okio/HashingSource.kt @@ -23,7 +23,8 @@ package okio * * In this example we use `HashingSource` with a [BufferedSource] to make reading * from the source easier. - * ``` + * + * ```java * HashingSource hashingSource = HashingSource.sha256(rawSource); * BufferedSource bufferedSource = Okio.buffer(hashingSource); * diff --git a/okio/src/jvmMain/kotlin/okio/HashingSink.kt b/okio/src/jvmMain/kotlin/okio/HashingSink.kt index 0c097d2008..e072835695 100644 --- a/okio/src/jvmMain/kotlin/okio/HashingSink.kt +++ b/okio/src/jvmMain/kotlin/okio/HashingSink.kt @@ -28,7 +28,8 @@ import javax.crypto.spec.SecretKeySpec * * In this example we use `HashingSink` with a [BufferedSink] to make writing to the * sink easier. - * ``` + * + * ```java * HashingSink hashingSink = HashingSink.sha256(s); * BufferedSink bufferedSink = Okio.buffer(hashingSink); * diff --git a/okio/src/jvmMain/kotlin/okio/HashingSource.kt b/okio/src/jvmMain/kotlin/okio/HashingSource.kt index e3d9191bd5..2a00b3ee43 100644 --- a/okio/src/jvmMain/kotlin/okio/HashingSource.kt +++ b/okio/src/jvmMain/kotlin/okio/HashingSource.kt @@ -29,7 +29,8 @@ import javax.crypto.spec.SecretKeySpec * * In this example we use `HashingSource` with a [BufferedSource] to make reading * from the source easier. - * ``` + * + * ```java * HashingSource hashingSource = HashingSource.sha256(rawSource); * BufferedSource bufferedSource = Okio.buffer(hashingSource); * diff --git a/okio/src/jvmMain/kotlin/okio/Timeout.kt b/okio/src/jvmMain/kotlin/okio/Timeout.kt index b5f5f35919..962bdbdbf6 100644 --- a/okio/src/jvmMain/kotlin/okio/Timeout.kt +++ b/okio/src/jvmMain/kotlin/okio/Timeout.kt @@ -135,7 +135,8 @@ actual open class Timeout { * * Here's a sample class that uses `awaitSignal()` to await a specific state. Note that the * call is made within a loop to avoid unnecessary waiting and to mitigate spurious notifications. - * ``` + * + * ```java * class Dice { * Random random = new Random(); * int latestTotal; @@ -219,7 +220,8 @@ actual open class Timeout { * * Here's a sample class that uses `waitUntilNotified()` to await a specific state. Note that the * call is made within a loop to avoid unnecessary waiting and to mitigate spurious notifications. - * ``` + * + * ```java * class Dice { * Random random = new Random(); * int latestTotal;