diff options
author | Carsten Weisse <[email protected]> | 2005-12-18 16:34:13 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2005-12-18 16:34:13 +0000 |
commit | 7acaf7c88a6d5fffbe0cc251a22a594667daa199 (patch) | |
tree | ff5f70b60985f7df4bfd4dc853c409b163bdf7c6 | |
parent | c0464012cfcb7e1b16f1b18c54d14eb288a9c02b (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.
-rw-r--r-- | src/jake2/util/Lib.java | 16 |
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) { |