From a6b0330c845d4edad87c7059bac56e194a276c6f Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 17 Nov 2024 14:31:45 +0200 Subject: UTF-8 support & fixed hard coded 'Alice' --- src/scalevalapokalypsi/utils/utils.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/scalevalapokalypsi/utils/utils.scala') diff --git a/src/scalevalapokalypsi/utils/utils.scala b/src/scalevalapokalypsi/utils/utils.scala index b1bac4d..ab262ad 100644 --- a/src/scalevalapokalypsi/utils/utils.scala +++ b/src/scalevalapokalypsi/utils/utils.scala @@ -1,6 +1,7 @@ package scalevalapokalypsi.utils import java.io.InputStream +import java.nio.charset.StandardCharsets /** Converts this string to an array of bytes (probably for transmission). * @@ -8,7 +9,7 @@ import java.io.InputStream * @return an array of bytes representing the string in UTF8. */ def stringToByteArray(str: String): Array[Byte] = - str.toVector.map(_.toByte).toArray + str.getBytes(StandardCharsets.UTF_8) /** Reads n characters from the given InputStream blockingly. * @@ -25,4 +26,4 @@ def getNCharsFromSocket(input: InputStream, n: Int): Option[String] = if res < 0 then failed = true i += res // TODO: better error handling - if failed then None else Some(String(buffer)) + if failed then None else Some(String(buffer, StandardCharsets.UTF_8)) -- cgit v1.2.3