aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/utils
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-17 14:31:45 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-17 14:31:45 +0200
commita6b0330c845d4edad87c7059bac56e194a276c6f (patch)
tree912a897b01a9eec59c552752e053255cf2a041ff /src/scalevalapokalypsi/utils
parent5060c66738898913ca880d83b0fdcd5be2e0b59d (diff)
downloadscalevalapokalypsi-a6b0330c845d4edad87c7059bac56e194a276c6f.tar.gz
scalevalapokalypsi-a6b0330c845d4edad87c7059bac56e194a276c6f.zip
UTF-8 support & fixed hard coded 'Alice'
Diffstat (limited to 'src/scalevalapokalypsi/utils')
-rw-r--r--src/scalevalapokalypsi/utils/utils.scala5
1 files changed, 3 insertions, 2 deletions
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))