Skip to content
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

Tag the language in code samples #1445

Merged
merged 2 commits into from
Feb 26, 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
2 changes: 1 addition & 1 deletion okio-nodefilesystem/src/main/kotlin/okio/FsJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions okio/src/commonMain/kotlin/okio/Buffer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ expect class Buffer() : BufferedSource, BufferedSink {
*
* New buffers are empty and have no segments:
*
* ```
* ```kotlin
* val buffer = Buffer()
* ```
*
* We append 7 bytes of data to the end of our empty buffer. Internally, the buffer allocates a
* 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', '?', '?', '?', ...]
Expand All @@ -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', '?', '?', '?', ...]
Expand All @@ -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))
*
Expand All @@ -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")
*
Expand All @@ -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"
Expand Down Expand Up @@ -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 ->
Expand Down
39 changes: 26 additions & 13 deletions okio/src/commonMain/kotlin/okio/BufferedSink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand All @@ -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(' ');
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(' ');
Expand All @@ -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(' ');
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
55 changes: 36 additions & 19 deletions okio/src/commonMain/kotlin/okio/BufferedSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
*
Expand All @@ -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");
*
Expand Down Expand Up @@ -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="),
Expand Down Expand Up @@ -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<Direction> options = TypedOptions.of(
* Arrays.asList(Direction.values()),
* (direction) -> ByteString.encodeUtf8(direction.name().toLowerCase(Locale.ROOT))
Expand Down Expand Up @@ -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(' ')
Expand All @@ -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(' ')
Expand All @@ -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")
Expand Down Expand Up @@ -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");
*
Expand Down Expand Up @@ -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.");
*
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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.");
Expand All @@ -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")
*
Expand Down
Loading