-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from aSemy/convert-jvm-to-use-kmp
Convert jvm to use kmp: implement reading/writing from Java input/output streams
- Loading branch information
Showing
10 changed files
with
151 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/commonMain/kotlin/com/charleskorn/kaml/internal/StringStreamDataWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.charleskorn.kaml.internal | ||
|
||
import okio.Buffer | ||
import okio.Source | ||
import org.snakeyaml.engine.v2.api.StreamDataWriter | ||
|
||
internal class StringStreamDataWriter( | ||
private val buffer: Buffer = Buffer(), | ||
) : StreamDataWriter, Source by buffer { | ||
override fun flush(): Unit = buffer.flush() | ||
|
||
override fun write(str: String) { | ||
buffer.writeUtf8(str) | ||
} | ||
|
||
override fun write(str: String, off: Int, len: Int) { | ||
buffer.writeUtf8(string = str, beginIndex = off, endIndex = off + len) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/commonMain/kotlin/com/charleskorn/kaml/internal/okio.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2018-2023 Charles Korn. | ||
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 | ||
https://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 com.charleskorn.kaml.internal | ||
|
||
import okio.Buffer | ||
import okio.BufferedSource | ||
import okio.ByteString.Companion.encodeUtf8 | ||
|
||
/** | ||
* Convert a UTF-8 String to a [BufferedSource]. | ||
*/ | ||
// https://github.com/square/okio/issues/774#issuecomment-703315013 | ||
internal fun String.bufferedSource( | ||
// charset: String = "utf8" // TODO convert charsets? | ||
): BufferedSource = Buffer().write(encodeUtf8()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters