[jboss-cvs] JBoss Messaging SVN: r4263 - in trunk: tests/src/org/jboss/messaging/tests/unit/core/util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 21 08:50:33 EDT 2008
Author: timfox
Date: 2008-05-21 08:50:33 -0400 (Wed, 21 May 2008)
New Revision: 4263
Modified:
trunk/src/main/org/jboss/messaging/util/SimpleString.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SimpleStringTest.java
Log:
Fixed unicode encoding on SimpleString
Modified: trunk/src/main/org/jboss/messaging/util/SimpleString.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/SimpleString.java 2008-05-21 11:07:40 UTC (rev 4262)
+++ trunk/src/main/org/jboss/messaging/util/SimpleString.java 2008-05-21 12:50:33 UTC (rev 4263)
@@ -10,7 +10,9 @@
import java.io.Serializable;
+import org.jboss.messaging.core.logging.Logger;
+
/**
*
* A SimpleString
@@ -24,6 +26,9 @@
public class SimpleString implements CharSequence, Serializable
{
private static final long serialVersionUID = 4204223851422244307L;
+
+ private static final Logger log = Logger.getLogger(SimpleString.class);
+
// Attributes
// ------------------------------------------------------------------------
@@ -49,9 +54,13 @@
{
char c = string.charAt(i);
- data[j++] = (byte)(c & 0xFF); // low byte
+ byte low = (byte)(c & 0xFF); // low byte
- data[j++] = (byte)(c >> 8 & 0xFF); // high byte
+ data[j++] = low;
+
+ byte high = (byte)(c >> 8 & 0xFF); // high byte
+
+ data[j++] = high;
}
str = string;
@@ -140,7 +149,11 @@
for (int i = 0; i < len; i++)
{
- chars[i] = (char)(data[j++] | data[j++] << 8);
+ int low = data[j++] & 0xFF;
+
+ int high = (data[j++] << 8) & 0xFF00 ;
+
+ chars[i] = (char)(low | high);
}
str = new String(chars);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SimpleStringTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SimpleStringTest.java 2008-05-21 11:07:40 UTC (rev 4262)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SimpleStringTest.java 2008-05-21 12:50:33 UTC (rev 4263)
@@ -192,41 +192,9 @@
assertFalse(new SimpleString("abcdef").equals(new SimpleString("abggcdef")));
}
-// public void testPerf() throws Exception
-// {
-// StringBuffer buff = new StringBuffer();
-//
-// for (int i = 0; i < 1000; i++)
-// {
-// buff.append('X');
-// }
-//
-// String s = buff.toString();
-//
-// long start = System.currentTimeMillis();
-//
-// long tot = 0;
-//
-// for (int i = 0; i < 1000000; i++)
-// {
-// SimpleString ss = new SimpleString(s);
-//
-// byte[] data = ss.getData();
-//
-// tot += data.length;
-// }
-//
-// long end = System.currentTimeMillis();
-//
-// double rate = 1000 * (double)1000000 / ( end - start);
-//
-// System.out.println("Rate: " + rate);
-// }
-
-
public void testUnicode() throws Exception
{
- String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
+ String myString = "abcdef&^*&!^ghijkl\uB5E2\uCAC7\uB2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
SimpleString s = new SimpleString(myString);
byte[] data = s.getData();
@@ -234,4 +202,15 @@
assertEquals(myString, s.toString());
}
+
+ public void testUnicodeWithSurrogates() throws Exception
+ {
+ String myString = "abcdef&^*&!^ghijkl\uD900\uDD00";
+
+ SimpleString s = new SimpleString(myString);
+ byte[] data = s.getData();
+ s = new SimpleString(data);
+
+ assertEquals(myString, s.toString());
+ }
}
More information about the jboss-cvs-commits
mailing list