aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/utils
diff options
context:
space:
mode:
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))