You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2011/04/09 13:47:07 UTC

svn commit: r1090572 - in /mina/branches/2.0.3/mina-core/src: main/java/org/apache/mina/core/buffer/ test/java/org/apache/mina/core/buffer/

Author: elecharny
Date: Sat Apr  9 11:47:07 2011
New Revision: 1090572

URL: http://svn.apache.org/viewvc?rev=1090572&view=rev
Log:
Added the missing putUnsignedInt() methods

Modified:
    mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
    mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java
    mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferWrapper.java
    mina/branches/2.0.3/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java

Modified: mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java?rev=1090572&r1=1090571&r2=1090572&view=diff
==============================================================================
--- mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java (original)
+++ mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java Sat Apr  9 11:47:07 2011
@@ -821,6 +821,36 @@ public abstract class AbstractIoBuffer e
      * {@inheritDoc}
      */
     @Override
+    public final IoBuffer putUnsignedInt(byte value) {
+        autoExpand(4);
+        buf().putInt( (int)((short)value&0x00ff) );
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final IoBuffer putUnsignedInt(short value) {
+        autoExpand(4);
+        buf().putInt( (int)((int)value&0x0000ffff) );
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final IoBuffer putUnsignedInt(int value) {
+        autoExpand(4);
+        buf().putInt( value );
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public final IoBuffer putUnsignedInt(long value) {
         autoExpand(4);
         buf().putInt( (int)(value&0x00000000ffffffff) );

Modified: mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java?rev=1090572&r1=1090571&r2=1090572&view=diff
==============================================================================
--- mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java (original)
+++ mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java Sat Apr  9 11:47:07 2011
@@ -792,6 +792,21 @@ public abstract class IoBuffer implement
     /**
      * Writes an unsigned int into the ByteBuffer
      */
+    public abstract IoBuffer putUnsignedInt(byte value);
+    
+    /**
+     * Writes an unsigned int into the ByteBuffer
+     */
+    public abstract IoBuffer putUnsignedInt(short value);
+    
+    /**
+     * Writes an unsigned int into the ByteBuffer
+     */
+    public abstract IoBuffer putUnsignedInt(int value);
+    
+    /**
+     * Writes an unsigned int into the ByteBuffer
+     */
     public abstract IoBuffer putUnsignedInt(long value);
 
     /**

Modified: mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferWrapper.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferWrapper.java?rev=1090572&r1=1090571&r2=1090572&view=diff
==============================================================================
--- mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferWrapper.java (original)
+++ mina/branches/2.0.3/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferWrapper.java Sat Apr  9 11:47:07 2011
@@ -354,6 +354,24 @@ public class IoBufferWrapper extends IoB
     }
     
     @Override
+    public IoBuffer putUnsignedInt(byte value) {
+        buf.putUnsignedInt(value);
+        return this;
+    }
+    
+    @Override
+    public IoBuffer putUnsignedInt(short value) {
+        buf.putUnsignedInt(value);
+        return this;
+    }
+    
+    @Override
+    public IoBuffer putUnsignedInt(int value) {
+        buf.putUnsignedInt(value);
+        return this;
+    }
+
+    @Override
     public IoBuffer putUnsignedInt(long value) {
         buf.putUnsignedInt(value);
         return this;

Modified: mina/branches/2.0.3/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0.3/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java?rev=1090572&r1=1090571&r2=1090572&view=diff
==============================================================================
--- mina/branches/2.0.3/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java (original)
+++ mina/branches/2.0.3/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java Sat Apr  9 11:47:07 2011
@@ -1331,4 +1331,29 @@ public class IoBufferTest {
 
         buf.flip();
     }
+    
+    @Test
+    public void testPutUnsignedInt() {
+        IoBuffer buf = IoBuffer.allocate(16);
+        byte b = (byte)0x80;                // We should get 0x00000080
+        short s = (short)0x8181;           // We should get 0x00008181
+        int i = 0x82828282;                // We should get 0x82828282
+        long l = 0x8383838383838383L;      // We should get 0x83838383
+        
+        buf.mark();
+
+        // Put the unsigned bytes
+        buf.putUnsignedInt( b );
+        buf.putUnsignedInt( s );
+        buf.putUnsignedInt( i );
+        buf.putUnsignedInt( l );
+
+        buf.reset();
+        
+        // Read back the unsigned bytes
+        assertEquals( 0x0000000000000080L, buf.getUnsignedInt() );
+        assertEquals( 0x0000000000008181L, buf.getUnsignedInt() );
+        assertEquals( 0x0000000082828282L, buf.getUnsignedInt() );
+        assertEquals( 0x0000000083838383L, buf.getUnsignedInt() );
+    }
 }