mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 01:54:04 +09:00
working ByteArray64Reader (UTF-8 compliant with proper surrogate pairing)
This commit is contained in:
@@ -26,7 +26,7 @@ object Load : ConsoleCommand {
|
||||
val disk = VDUtil.readDiskArchive(file, charset = charset)
|
||||
|
||||
val metaFile = VDUtil.getFile(disk, VDUtil.VDPath("savegame", charset))!!
|
||||
val metaReader = ByteArray64Reader(metaFile.contents.serialize().array)
|
||||
val metaReader = ByteArray64Reader(metaFile.contents.serialize().array, charset)
|
||||
val meta = Common.jsoner.fromJson(JsonValue::class.java, metaReader)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.serialise.ByteArray64Reader
|
||||
import net.torvald.terrarum.serialise.ByteArray64Writer
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-08-31.
|
||||
*/
|
||||
object ReaderTest : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val textfile = File("./work_files/utftest.txt")
|
||||
val text = textfile.readText()
|
||||
|
||||
val writer = ByteArray64Writer(Charsets.UTF_8)
|
||||
writer.write(text); writer.flush(); writer.close()
|
||||
|
||||
val ba = writer.toByteArray64()
|
||||
|
||||
val reader = ByteArray64Reader(ba, Charsets.UTF_8)
|
||||
val readText = reader.readText(); reader.close()
|
||||
|
||||
println(readText)
|
||||
val outfile = File("./work_files/utftest-roundtrip.txt")
|
||||
outfile.writeText(readText, Charsets.UTF_8)
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: readertest")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user