aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2
diff options
context:
space:
mode:
authorCarsten Weisse <[email protected]>2005-12-18 16:34:13 +0000
committerCarsten Weisse <[email protected]>2005-12-18 16:34:13 +0000
commit7acaf7c88a6d5fffbe0cc251a22a594667daa199 (patch)
treeff5f70b60985f7df4bfd4dc853c409b163bdf7c6 /src/jake2
parentc0464012cfcb7e1b16f1b18c54d14eb288a9c02b (diff)
convert a java string to byte[] with 8bit latin 1.
avoid String.getBytes() because it is using system specific character encoding. Network messages can fail, see rcon on a linux system.
Diffstat (limited to 'src/jake2')
-rw-r--r--src/jake2/util/Lib.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/jake2/util/Lib.java b/src/jake2/util/Lib.java
index 48c0483..c65e17f 100644
--- a/src/jake2/util/Lib.java
+++ b/src/jake2/util/Lib.java
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 09.12.2003 by RST.
-// $Id: Lib.java,v 1.16 2005-12-16 21:19:42 salomo Exp $
+// $Id: Lib.java,v 1.17 2005-12-18 16:34:13 cawe Exp $
package jake2.util;
@@ -301,6 +301,20 @@ public class Lib {
return out;
}
+
+ /**
+ * convert a java string to byte[] with 8bit latin 1
+ *
+ * avoid String.getBytes() because it is using system specific character encoding.
+ */
+ public static byte[] stringToBytes(String value) {
+ try {
+ return value.getBytes("ISO-8859-1");
+ } catch (UnsupportedEncodingException e) {
+ // can't happen: Latin 1 is a standard encoding
+ return null;
+ }
+ }
/** Helper method that savely handles the null termination of old C String data. */
public static String CtoJava(String old) {