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 14:48:01 UTC
svn commit: r1090578 - 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 12:48:00 2011
New Revision: 1090578
URL: http://svn.apache.org/viewvc?rev=1090578&view=rev
Log:
Added the putUnsignedInt( index, val ) method, and tests
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=1090578&r1=1090577&r2=1090578&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 12:48:00 2011
@@ -831,6 +831,16 @@ public abstract class AbstractIoBuffer e
* {@inheritDoc}
*/
@Override
+ public final IoBuffer putUnsignedInt(int index, byte value) {
+ autoExpand(index, 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) );
@@ -841,6 +851,16 @@ public abstract class AbstractIoBuffer e
* {@inheritDoc}
*/
@Override
+ public final IoBuffer putUnsignedInt(int index, short value) {
+ autoExpand(index, 4);
+ buf().putInt( (int)((int)value&0x0000ffff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public final IoBuffer putUnsignedInt(int value) {
autoExpand(4);
buf().putInt( value );
@@ -851,6 +871,16 @@ public abstract class AbstractIoBuffer e
* {@inheritDoc}
*/
@Override
+ public final IoBuffer putUnsignedInt(int index, int value) {
+ autoExpand(index, 4);
+ buf().putInt( value );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public final IoBuffer putUnsignedInt(long value) {
autoExpand(4);
buf().putInt( (int)(value&0x00000000ffffffff) );
@@ -861,6 +891,16 @@ public abstract class AbstractIoBuffer e
* {@inheritDoc}
*/
@Override
+ public final IoBuffer putUnsignedInt(int index, long value) {
+ autoExpand(index, 4);
+ buf().putInt( (int)(value&0x00000000ffffffffL) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public final int getInt(int index) {
return buf().getInt(index);
}
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=1090578&r1=1090577&r2=1090578&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 12:48:00 2011
@@ -795,19 +795,39 @@ public abstract class IoBuffer implement
public abstract IoBuffer putUnsignedInt(byte value);
/**
+ * Writes an unsigned int into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsignedInt(int index, byte value);
+
+ /**
* Writes an unsigned int into the ByteBuffer
*/
public abstract IoBuffer putUnsignedInt(short value);
/**
+ * Writes an unsigned int into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsignedInt(int index, short value);
+
+ /**
* Writes an unsigned int into the ByteBuffer
*/
public abstract IoBuffer putUnsignedInt(int value);
/**
+ * Writes an unsigned int into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsignedInt(int index, int value);
+
+ /**
* Writes an unsigned int into the ByteBuffer
*/
public abstract IoBuffer putUnsignedInt(long value);
+
+ /**
+ * Writes an unsigned int into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsignedInt(int index, long value);
/**
* @see ByteBuffer#getInt(int)
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=1090578&r1=1090577&r2=1090578&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 12:48:00 2011
@@ -360,22 +360,46 @@ public class IoBufferWrapper extends IoB
}
@Override
+ public IoBuffer putUnsignedInt(int index, byte value) {
+ buf.putUnsignedInt(index, value);
+ return this;
+ }
+
+ @Override
public IoBuffer putUnsignedInt(short value) {
buf.putUnsignedInt(value);
return this;
}
@Override
+ public IoBuffer putUnsignedInt(int index, short value) {
+ buf.putUnsignedInt(index, value);
+ return this;
+ }
+
+ @Override
public IoBuffer putUnsignedInt(int value) {
buf.putUnsignedInt(value);
return this;
}
+
+ @Override
+ public IoBuffer putUnsignedInt(int index, int value) {
+ buf.putUnsignedInt(index, value);
+ return this;
+ }
@Override
public IoBuffer putUnsignedInt(long value) {
buf.putUnsignedInt(value);
return this;
}
+
+ @Override
+ public IoBuffer putUnsignedInt(int index, long value) {
+ buf.putUnsignedInt(index, value);
+ return this;
+ }
@Override
public int getInt(int index) {
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=1090578&r1=1090577&r2=1090578&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 12:48:00 2011
@@ -1356,4 +1356,29 @@ public class IoBufferTest {
assertEquals( 0x0000000082828282L, buf.getUnsignedInt() );
assertEquals( 0x0000000083838383L, buf.getUnsignedInt() );
}
+
+ @Test
+ public void testPutUnsignedIntPosition() {
+ 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( 3, b );
+ buf.putUnsignedInt( 2, s );
+ buf.putUnsignedInt( 1, i );
+ buf.putUnsignedInt( 0, l );
+
+ buf.reset();
+
+ // Read back the unsigned bytes
+ assertEquals( 0x0000000000000080L, buf.getUnsignedInt() );
+ assertEquals( 0x0000000000008181L, buf.getUnsignedInt() );
+ assertEquals( 0x0000000082828282L, buf.getUnsignedInt() );
+ assertEquals( 0x0000000083838383L, buf.getUnsignedInt() );
+ }
}