aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCarsten Weisse <[email protected]>2005-12-18 22:10:13 +0000
committerCarsten Weisse <[email protected]>2005-12-18 22:10:13 +0000
commit90135445c8833ff11a31bf37fa09a0b265904b55 (patch)
tree759086613c7c5dcab243ce690d7a9b8556fad534 /src
parent2b242d9d77cb7b04538f3434bdc5c95a7e1d763c (diff)
byte[] <--> String
with latin 1 alias ISO-8859-1
Diffstat (limited to 'src')
-rw-r--r--src/jake2/client/CL.java8
-rw-r--r--src/jake2/client/CL_inv.java11
-rw-r--r--src/jake2/client/Key.java4
-rw-r--r--src/jake2/qcommon/Cbuf.java4
-rw-r--r--src/jake2/qcommon/MSG.java4
-rw-r--r--src/jake2/qcommon/Netchan.java5
-rw-r--r--src/jake2/qcommon/SZ.java5
-rw-r--r--src/jake2/server/SV_MAIN.java4
-rw-r--r--src/jake2/server/SV_SEND.java4
-rw-r--r--src/jake2/util/Lib.java20
10 files changed, 43 insertions, 26 deletions
diff --git a/src/jake2/client/CL.java b/src/jake2/client/CL.java
index a4f18bb..51f4dcd 100644
--- a/src/jake2/client/CL.java
+++ b/src/jake2/client/CL.java
@@ -2,7 +2,7 @@
* CL.java
* Copyright (C) 2004
*
- * $Id: CL.java,v 1.28 2005-12-18 16:43:51 cawe Exp $
+ * $Id: CL.java,v 1.29 2005-12-18 22:10:10 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -720,9 +720,9 @@ public final class CL {
// send a disconnect message to the server
fin = (char) Defines.clc_stringcmd + "disconnect";
- Netchan.Transmit(Globals.cls.netchan, fin.length(), fin.getBytes());
- Netchan.Transmit(Globals.cls.netchan, fin.length(), fin.getBytes());
- Netchan.Transmit(Globals.cls.netchan, fin.length(), fin.getBytes());
+ Netchan.Transmit(Globals.cls.netchan, fin.length(), Lib.stringToBytes(fin));
+ Netchan.Transmit(Globals.cls.netchan, fin.length(), Lib.stringToBytes(fin));
+ Netchan.Transmit(Globals.cls.netchan, fin.length(), Lib.stringToBytes(fin));
ClearState();
diff --git a/src/jake2/client/CL_inv.java b/src/jake2/client/CL_inv.java
index ee7764a..7b771f1 100644
--- a/src/jake2/client/CL_inv.java
+++ b/src/jake2/client/CL_inv.java
@@ -2,7 +2,7 @@
* CL_fx.java
* Copyright (C) 2004
*
- * $Id: CL_inv.java,v 1.2 2004-09-22 19:22:08 salomo Exp $
+ * $Id: CL_inv.java,v 1.3 2005-12-18 22:10:10 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -31,6 +31,7 @@ import jake2.Defines;
import jake2.Globals;
import jake2.qcommon.Com;
import jake2.qcommon.MSG;
+import jake2.util.Lib;
import jake2.util.Vargs;
/**
@@ -58,12 +59,12 @@ public class CL_inv {
}
}
- static void SetStringHighBit(String s) {
- byte[] b = s.getBytes();
+ static String getHighBitString(String s) {
+ byte[] b = Lib.stringToBytes(s);
for (int i = 0; i < b.length; i++) {
b[i] = (byte) (b[i] | 128);
}
- s = new String(b);
+ return Lib.bytesToString(b);
}
/*
@@ -131,7 +132,7 @@ public class CL_inv {
string = Com.sprintf("%6s %3i %s", new Vargs(3).add(bind).add(Globals.cl.inventory[item]).add(
Globals.cl.configstrings[Defines.CS_ITEMS + item]));
if (item != selected)
- SetStringHighBit(string);
+ string = getHighBitString(string);
else // draw a blinky cursor by the selected item
{
if (((int) (Globals.cls.realtime * 10) & 1) != 0)
diff --git a/src/jake2/client/Key.java b/src/jake2/client/Key.java
index 1787262..f896a2c 100644
--- a/src/jake2/client/Key.java
+++ b/src/jake2/client/Key.java
@@ -2,7 +2,7 @@
* Key.java
* Copyright (C) 2003
*
- * $Id: Key.java,v 1.11 2005-06-07 12:57:21 hzi Exp $
+ * $Id: Key.java,v 1.12 2005-12-18 22:10:12 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -704,7 +704,7 @@ public class Key extends Globals {
} else return;
key_lines[edit_line][1] = '/';
- byte[] bytes = s.getBytes();
+ byte[] bytes = Lib.stringToBytes(s);
System.arraycopy(bytes, 0, key_lines[edit_line], 2, bytes.length);
key_linepos = bytes.length + 2;
key_lines[edit_line][key_linepos++] = ' ';
diff --git a/src/jake2/qcommon/Cbuf.java b/src/jake2/qcommon/Cbuf.java
index 593c058..1d4c4b1 100644
--- a/src/jake2/qcommon/Cbuf.java
+++ b/src/jake2/qcommon/Cbuf.java
@@ -2,7 +2,7 @@
* Cbuf.java
* Copyright (C) 2003
*
- * $Id: Cbuf.java,v 1.7 2005-02-19 11:12:42 salomo Exp $
+ * $Id: Cbuf.java,v 1.8 2005-12-18 22:10:09 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -145,7 +145,7 @@ public final class Cbuf {
Com.Printf("Cbuf_AddText: overflow\n");
return;
}
- SZ.Write(Globals.cmd_text, text.getBytes(), l);
+ SZ.Write(Globals.cmd_text, Lib.stringToBytes(text), l);
}
/**
diff --git a/src/jake2/qcommon/MSG.java b/src/jake2/qcommon/MSG.java
index 4d5332b..99f9e1c 100644
--- a/src/jake2/qcommon/MSG.java
+++ b/src/jake2/qcommon/MSG.java
@@ -19,7 +19,7 @@
*/
// Created on 29.11.2003 by RST.
-// $Id: MSG.java,v 1.7 2005-02-19 21:20:47 salomo Exp $
+// $Id: MSG.java,v 1.8 2005-12-18 22:10:02 cawe Exp $
package jake2.qcommon;
import jake2.Globals;
@@ -85,7 +85,7 @@ public class MSG extends Globals {
if (s == null)
x = "";
- SZ.Write(sb, x.getBytes());
+ SZ.Write(sb, Lib.stringToBytes(x));
WriteByte(sb, 0);
//Com.dprintln("MSG.WriteString:" + s.replace('\0', '@'));
}
diff --git a/src/jake2/qcommon/Netchan.java b/src/jake2/qcommon/Netchan.java
index 202a499..2157d12 100644
--- a/src/jake2/qcommon/Netchan.java
+++ b/src/jake2/qcommon/Netchan.java
@@ -2,7 +2,7 @@
* NetChannel.java
* Copyright (C) 2003
*
- * $Id: Netchan.java,v 1.6 2005-07-01 14:20:56 hzi Exp $
+ * $Id: Netchan.java,v 1.7 2005-12-18 22:10:08 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -31,6 +31,7 @@ import jake2.game.cvar_t;
import jake2.server.SV_MAIN;
import jake2.sys.NET;
import jake2.sys.Timer;
+import jake2.util.Lib;
/**
* Netchan
@@ -140,7 +141,7 @@ public final class Netchan extends SV_MAIN {
}
public static void OutOfBandPrint(int net_socket, netadr_t adr, String s) {
- Netchan_OutOfBand(net_socket, adr, s.length(), s.getBytes());
+ Netchan_OutOfBand(net_socket, adr, s.length(), Lib.stringToBytes(s));
}
/*
diff --git a/src/jake2/qcommon/SZ.java b/src/jake2/qcommon/SZ.java
index 46ac97b..a870c62 100644
--- a/src/jake2/qcommon/SZ.java
+++ b/src/jake2/qcommon/SZ.java
@@ -2,7 +2,7 @@
* SZ.java
* Copyright (C) 2003
*
- * $Id: SZ.java,v 1.5 2005-02-06 19:26:50 salomo Exp $
+ * $Id: SZ.java,v 1.6 2005-12-18 22:10:07 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package jake2.qcommon;
import jake2.Defines;
+import jake2.util.Lib;
/**
* SZ
@@ -90,7 +91,7 @@ public final class SZ {
public static void Print(sizebuf_t buf, String data) {
Com.dprintln("SZ.print():<" + data + ">" );
int length = data.length();
- byte str[] = data.getBytes();
+ byte str[] = Lib.stringToBytes(data);
if (buf.cursize != 0) {
diff --git a/src/jake2/server/SV_MAIN.java b/src/jake2/server/SV_MAIN.java
index bf12986..e9b876e 100644
--- a/src/jake2/server/SV_MAIN.java
+++ b/src/jake2/server/SV_MAIN.java
@@ -19,7 +19,7 @@
*/
// Created on 13.01.2004 by RST.
-// $Id: SV_MAIN.java,v 1.13 2005-12-18 17:25:09 cawe Exp $
+// $Id: SV_MAIN.java,v 1.14 2005-12-18 22:10:13 cawe Exp $
package jake2.server;
import jake2.Defines;
@@ -458,7 +458,7 @@ public class SV_MAIN {
Com.BeginRedirect(Defines.RD_PACKET, SV_SEND.sv_outputbuf,
Defines.SV_OUTPUTBUF_LENGTH, new Com.RD_Flusher() {
public void rd_flush(int target, StringBuffer buffer) {
- SV_SEND.SV_FlushRedirect(target, buffer.toString().getBytes());
+ SV_SEND.SV_FlushRedirect(target, Lib.stringToBytes(buffer.toString()));
}
});
diff --git a/src/jake2/server/SV_SEND.java b/src/jake2/server/SV_SEND.java
index 12c762f..df1bc55 100644
--- a/src/jake2/server/SV_SEND.java
+++ b/src/jake2/server/SV_SEND.java
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 17.01.2004 by RST.
-// $Id: SV_SEND.java,v 1.9 2005-12-16 21:18:23 salomo Exp $
+// $Id: SV_SEND.java,v 1.10 2005-12-18 22:10:12 cawe Exp $
package jake2.server;
@@ -47,7 +47,7 @@ public class SV_SEND {
public static void SV_FlushRedirect(int sv_redirected, byte outputbuf[]) {
if (sv_redirected == Defines.RD_PACKET) {
String s = ("print\n" + Lib.CtoJava(outputbuf));
- Netchan.Netchan_OutOfBand(Defines.NS_SERVER, Globals.net_from, s.length(), s.getBytes());
+ Netchan.Netchan_OutOfBand(Defines.NS_SERVER, Globals.net_from, s.length(), Lib.stringToBytes(s));
}
else if (sv_redirected == Defines.RD_CLIENT) {
MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_print);
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) {