diff options
author | Carsten Weisse <[email protected]> | 2005-12-18 22:10:13 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2005-12-18 22:10:13 +0000 |
commit | 90135445c8833ff11a31bf37fa09a0b265904b55 (patch) | |
tree | 759086613c7c5dcab243ce690d7a9b8556fad534 /src/jake2/util/Lib.java | |
parent | 2b242d9d77cb7b04538f3434bdc5c95a7e1d763c (diff) |
byte[] <--> String
with latin 1 alias ISO-8859-1
Diffstat (limited to 'src/jake2/util/Lib.java')
-rw-r--r-- | src/jake2/util/Lib.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/jake2/util/Lib.java b/src/jake2/util/Lib.java index c65e17f..269f039 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.17 2005-12-18 16:34:13 cawe Exp $ +// $Id: Lib.java,v 1.18 2005-12-18 22:10:12 cawe Exp $ package jake2.util; @@ -208,12 +208,12 @@ public class Lib { return; int diff = len - s.length(); if (diff > 0) { - f.write(s.getBytes()); + f.write(stringToBytes(s)); f.write(nullfiller, 0, diff); } else - f.write(s.getBytes(), 0, len); + f.write(stringToBytes(s), 0, len); } /** Like in libc */ @@ -315,6 +315,20 @@ public class Lib { return null; } } + + /** + * convert a byte[] with 8bit latin 1 to java string + * + * avoid new String(bytes) because it is using system specific character encoding. + */ + public static String bytesToString(byte[] value) { + try { + return new String(value, "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) { |