db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r966452 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/
Date Wed, 21 Jul 2010 22:57:27 GMT
Author: kmarsden
Date: Wed Jul 21 22:57:27 2010
New Revision: 966452

URL: http://svn.apache.org/viewvc?rev=966452&view=rev
Log:
DERBY-4746  (Server) Implement UTF8 support on DRDA

Made a small change to the Utf8CcsidManagerTest to accommodate for the fact that the convertToJavaString
takes the offset and numCount in bytes and not characters. 

Contributed by Tiago R Espinha (tiago dot derby at yahoo dot co dot uk)


Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/CcsidManager.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EbcdicCcsidManager.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Utf8CcsidManager.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/Utf8CcsidManagerTest.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/CcsidManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/CcsidManager.java?rev=966452&r1=966451&r2=966452&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/CcsidManager.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/CcsidManager.java Wed Jul 21
22:57:27 2010
@@ -32,6 +32,10 @@ abstract class CcsidManager
   // bytes containing the character representation "value" for the particular ccsid.
   byte[] numToCharRepresentation;
 
+  /* DRDA CCSID levels for UTF8 and EBCDIC */
+  public static final int UTF8_CCSID = 1208;
+  public static final int EBCDIC_CCSID = 500;
+  
   CcsidManager (byte space, byte dot, byte[] numToCharRepresentation)
   {
     this.space = space;
@@ -39,7 +43,13 @@ abstract class CcsidManager
     this.numToCharRepresentation = numToCharRepresentation;
   }
 
-
+  /**
+   * Returns the length in bytes for the String str using a particular ccsid.
+   * @param str The Java String from which to obtain the length.
+   * @return The length in bytes of the String str.
+   */
+  abstract int getByteLength (String str);
+  
   // Convert a Java String into bytes for a particular ccsid.
   //
   // @param sourceString A Java String to convert.

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java?rev=966452&r1=966451&r2=966452&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java Wed Jul 21 22:57:27
2010
@@ -902,7 +902,7 @@ class DDMWriter
 	 */
 	void writeScalarString (int codePoint, String string)
 	{
-		int stringLength = string.length();
+		int stringLength = ccsidManager.getByteLength(string);
 		ensureLength ((stringLength * 2)  + 4);
 		buffer.putShort((short) (stringLength + 4));
 		buffer.putShort((short) codePoint);

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EbcdicCcsidManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EbcdicCcsidManager.java?rev=966452&r1=966451&r2=966452&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EbcdicCcsidManager.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EbcdicCcsidManager.java Wed Jul
21 22:57:27 2010
@@ -170,4 +170,8 @@ class EbcdicCcsidManager extends CcsidMa
 		return new String (theChars);
 	}
 
+    int getByteLength(String str) {
+        return str.length();
+    }
+
 }

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Utf8CcsidManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Utf8CcsidManager.java?rev=966452&r1=966451&r2=966452&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Utf8CcsidManager.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Utf8CcsidManager.java Wed Jul
21 22:57:27 2010
@@ -67,9 +67,12 @@ public class Utf8CcsidManager extends Cc
         return null;
     }
 
+    /**
+     * Offset and numToConvert are given in terms of bytes! Not characters!
+     */
     public String convertToJavaString(byte[] sourceBytes, int offset, int numToConvert) {
         try {
-            return new String(sourceBytes,"UTF-8").substring(offset, offset+numToConvert);
+            return new String(sourceBytes, offset, numToConvert, "UTF-8");
         } catch (UnsupportedEncodingException e) {
             if (SanityManager.DEBUG) {
                 SanityManager.THROWASSERT("Could not convert byte[] to Java String using
UTF-8 encoding with offset",e);
@@ -90,4 +93,15 @@ public class Utf8CcsidManager extends Cc
         buffer.put(convertFromJavaString(sourceString));
     }
 
+    int getByteLength(String str) {
+        try {
+            return str.getBytes("UTF-8").length;
+        } catch (UnsupportedEncodingException e) {
+            if (SanityManager.DEBUG) {
+                SanityManager.THROWASSERT("Could not obtain byte length of Java String in
Utf8CcsidManager",e);
+            }
+        }
+        return -1;
+    }
+
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/Utf8CcsidManagerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/Utf8CcsidManagerTest.java?rev=966452&r1=966451&r2=966452&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/Utf8CcsidManagerTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/Utf8CcsidManagerTest.java
Wed Jul 21 22:57:27 2010
@@ -88,7 +88,7 @@ public class Utf8CcsidManagerTest extend
         assertEquals(ucs2String, convertedString);
         
         // Convert just the two characters as offset above and compare
-        String convertedOffset = ccsidManager.convertToJavaString(utf8Bytes, 1, 2);
+        String convertedOffset = ccsidManager.convertToJavaString(utf8Bytes, 3, 6);
         assertEquals(offsetUcs2String, convertedOffset);
     }
     



Mime
View raw message