[jboss-cvs] JBoss Messaging SVN: r4114 - in trunk: src/main/org/jboss/messaging/core/remoting/impl/codec and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 24 12:38:22 EDT 2008


Author: timfox
Date: 2008-04-24 12:38:22 -0400 (Thu, 24 Apr 2008)
New Revision: 4114

Modified:
   trunk/src/main/org/jboss/messaging/core/remoting/impl/PacketDispatcherImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java
Log:
Don't encode strings as utf8


Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/PacketDispatcherImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/PacketDispatcherImpl.java	2008-04-24 15:39:11 UTC (rev 4113)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/PacketDispatcherImpl.java	2008-04-24 16:38:22 UTC (rev 4114)
@@ -8,7 +8,6 @@
 
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.NO_ID_SET;
 
-import java.io.Serializable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -145,7 +144,7 @@
    {
       if (log.isDebugEnabled())
       {
-         StringBuffer buf = new StringBuffer("Registered PacketHandlers (Ê" + this + "):\n");
+         StringBuffer buf = new StringBuffer("Registered PacketHandlers (" + this + "):\n");
          Iterator<Entry<Long, PacketHandler>> iterator = handlers.entrySet().iterator();
          while (iterator.hasNext())
          {

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java	2008-04-24 15:39:11 UTC (rev 4113)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java	2008-04-24 16:38:22 UTC (rev 4114)
@@ -39,6 +39,8 @@
 
    public static final int LONG_LENGTH = 8;
    
+   public static final int CHAR_LENGTH = 2;
+   
    public static final int HEADER_LENGTH =
    	BYTE_LENGTH + LONG_LENGTH + LONG_LENGTH + LONG_LENGTH + BOOLEAN_LENGTH;
    
@@ -93,12 +95,11 @@
    {
       if (nullableString == null)
       {
-         return 1; // NULL_STRING byte
+         return BYTE_LENGTH; // NULL_STRING byte
       }
       else
       {
-         return nullableString.getBytes().length + 2;// NOT_NULL_STRING +
-         // NULL_BYTE
+         return BYTE_LENGTH + INT_LENGTH + CHAR_LENGTH * nullableString.length();
       }
    }
    

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java	2008-04-24 15:39:11 UTC (rev 4113)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java	2008-04-24 16:38:22 UTC (rev 4114)
@@ -6,10 +6,10 @@
  */
 package org.jboss.messaging.core.remoting.impl.codec;
 
-import java.nio.charset.CharacterCodingException;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * 
  * @version <tt>$Revision$</tt>
  * 
@@ -42,11 +42,14 @@
 
    boolean getBoolean();
 
-   void putNullableString(String nullableString)
-         throws CharacterCodingException;
+   void putNullableString(String nullableString);
 
-   String getNullableString() throws CharacterCodingException;
+   String getNullableString();
    
+   void putString(String nullableString);
+
+   String getString();
+   
    void rewind();
 
    byte[] array();

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java	2008-04-24 15:39:11 UTC (rev 4113)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java	2008-04-24 16:38:22 UTC (rev 4114)
@@ -53,6 +53,8 @@
    {
       String text = in.getNullableString();
 
+      
+      
       return new TextPacket(text);
    }
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java	2008-04-24 15:39:11 UTC (rev 4113)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java	2008-04-24 16:38:22 UTC (rev 4114)
@@ -9,7 +9,6 @@
 import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.FALSE;
 import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.TRUE;
 
-import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
@@ -17,10 +16,18 @@
 import org.apache.mina.common.IoBuffer;
 import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
 
+/**
+ * 
+ * A BufferWrapper
+ * 
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
 public class BufferWrapper implements RemotingBuffer
 {
    // Constants -----------------------------------------------------
-
+	
    // used to terminate encoded Strings
    public static final byte NULL_BYTE = (byte) 0;
 
@@ -63,27 +70,27 @@
       return buffer.remaining();
    }
 
-   public void put(byte byteValue)
+   public void put(final byte byteValue)
    {
       buffer.put(byteValue);
    }
 
-   public void put(byte[] byteArray)
+   public void put(final byte[] byteArray)
    {
       buffer.put(byteArray);
    }
 
-   public void putInt(int intValue)
+   public void putInt(final int intValue)
    {
       buffer.putInt(intValue);
    }
 
-   public void putLong(long longValue)
+   public void putLong(final long longValue)
    {
       buffer.putLong(longValue);
    }
 
-   public void putFloat(float floatValue)
+   public void putFloat(final float floatValue)
    {
       buffer.putFloat(floatValue);
    }
@@ -113,7 +120,7 @@
       return buffer.getFloat();
    }
 
-   public void putBoolean(boolean b)
+   public void putBoolean(final boolean b)
    {
       if (b)
       {
@@ -130,33 +137,54 @@
       return (b == TRUE);
    }
 
-   public void putNullableString(String nullableString)
-         throws CharacterCodingException
+   public void putNullableString(final String nullableString)
    {
-
       if (nullableString == null)
       {
          buffer.put(NULL_STRING);
-      } else
+      }
+      else
       {
          buffer.put(NOT_NULL_STRING);
-         buffer.putString(nullableString, UTF_8_ENCODER);
-         buffer.put(NULL_BYTE);
+         putString(nullableString);
       }
    }
 
-   public String getNullableString() throws CharacterCodingException
+   public String getNullableString()
    {
       byte check = buffer.get();
       if (check == NULL_STRING)
       {
          return null;
-      } else
+      }
+      else
       {
-         assert check == NOT_NULL_STRING;
+         return getString();
+      }
+   }
+   
+   public void putString(final String string)
+   {
+   	int len = string.length();
+      buffer.putInt(len);
+      for (int i = 0; i < len; i++)
+      {   
+      	buffer.putChar(string.charAt(i));
+      }
+   }
 
-         return buffer.getString(UTF_8_DECODER);
+   public String getString()
+   {
+   	int len = buffer.getInt();
+      char[] chars = new char[len];
+      for (int i = 0; i < len; i++)
+      {
+      	chars[i] = buffer.getChar();
       }
+                     
+      String string =  new String(chars);
+      
+      return string;
    }
    
    public void rewind()

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java	2008-04-24 15:39:11 UTC (rev 4113)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java	2008-04-24 16:38:22 UTC (rev 4114)
@@ -308,6 +308,7 @@
       buffer.rewind();
 
       Packet decodedPacket = decode(buffer, codec, bodyLength);
+      
       return decodedPacket;
    }
 
@@ -322,8 +323,6 @@
 
       assertNotNull(encodedMessage);
 
-      log.info("encoded message is " + encodedMessage);
-
       assertTrue(encodedMessage instanceof IoBuffer);
 
       RemotingBuffer buff = new BufferWrapper((IoBuffer) encodedMessage);




More information about the jboss-cvs-commits mailing list