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:24:41 UTC
svn commit: r1090567 - 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:24:41 2011
New Revision: 1090567
URL: http://svn.apache.org/viewvc?rev=1090567&view=rev
Log:
Added the putUnsigned() and putUnsigned(int) methods 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=1090567&r1=1090566&r2=1090567&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:24:41 2011
@@ -514,6 +514,78 @@ public abstract class AbstractIoBuffer e
/**
* {@inheritDoc}
*/
+ public IoBuffer putUnsigned(byte value) {
+ autoExpand(1);
+ buf().put( (byte)(value & 0xff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(int index, byte value) {
+ autoExpand(index, 1);
+ buf().put( index, (byte)(value & 0xff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(short value) {
+ autoExpand(1);
+ buf().put( (byte)(value & 0x00ff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(int index, short value) {
+ autoExpand(index, 1);
+ buf().put( index, (byte)(value & 0x00ff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(int value) {
+ autoExpand(1);
+ buf().put( (byte)(value & 0x000000ff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(int index, int value) {
+ autoExpand(index, 1);
+ buf().put( index, (byte)(value & 0x000000ff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(long value) {
+ autoExpand(1);
+ buf().put( (byte)(value & 0x00000000000000ffL) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IoBuffer putUnsigned(int index, long value) {
+ autoExpand(index, 1);
+ buf().put( index, (byte)(value & 0x00000000000000ffL) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public final byte get(int index) {
return buf().get(index);
@@ -749,6 +821,16 @@ public abstract class AbstractIoBuffer e
* {@inheritDoc}
*/
@Override
+ public final IoBuffer putUnsignedInt(long value) {
+ autoExpand(4);
+ buf().putInt( (int)(value&0x00000000ffffffff) );
+ 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=1090567&r1=1090566&r2=1090567&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:24:41 2011
@@ -748,6 +748,51 @@ public abstract class IoBuffer implement
* @see ByteBuffer#putInt(int)
*/
public abstract IoBuffer putInt(int value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer
+ */
+ public abstract IoBuffer putUnsigned(byte value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsigned(int index, byte value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer
+ */
+ public abstract IoBuffer putUnsigned(short value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsigned(int index, short value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer
+ */
+ public abstract IoBuffer putUnsigned(int value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsigned(int index, int value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer
+ */
+ public abstract IoBuffer putUnsigned(long value);
+
+ /**
+ * Writes an unsigned byte into the ByteBuffer at a specified position
+ */
+ public abstract IoBuffer putUnsigned(int index, long value);
+
+ /**
+ * Writes an unsigned int into the ByteBuffer
+ */
+ public abstract IoBuffer putUnsignedInt(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=1090567&r1=1090566&r2=1090567&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:24:41 2011
@@ -352,6 +352,12 @@ public class IoBufferWrapper extends IoB
buf.putInt(value);
return this;
}
+
+ @Override
+ public IoBuffer putUnsignedInt(long value) {
+ buf.putUnsignedInt(value);
+ return this;
+ }
@Override
public int getInt(int index) {
@@ -897,4 +903,52 @@ public class IoBufferWrapper extends IoB
buf.putEnumSetLong(index, set);
return this;
}
+
+ @Override
+ public IoBuffer putUnsigned(byte value) {
+ buf.putUnsigned(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(int index, byte value) {
+ buf.putUnsigned(index, value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(short value) {
+ buf.putUnsigned(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(int index, short value) {
+ buf.putUnsigned(index, value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(int value) {
+ buf.putUnsigned(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(int index, int value) {
+ buf.putUnsigned(index, value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(long value) {
+ buf.putUnsigned(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsigned(int index, long value) {
+ buf.putUnsigned(index, 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=1090567&r1=1090566&r2=1090567&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:24:41 2011
@@ -932,6 +932,56 @@ public class IoBufferTest {
buf.reset();
assertEquals(0xCDB3D0A4L, buf.getUnsignedInt());
}
+
+ @Test
+ public void testPutUnsigned() {
+ IoBuffer buf = IoBuffer.allocate(4);
+ byte b = (byte)0x80; // We should get 0x0080
+ short s = (short)0x8F81; // We should get 0x0081
+ int i = 0x8FFFFF82; // We should get 0x0082
+ long l = 0x8FFFFFFFFFFFFF83L; // We should get 0x0083
+
+ buf.mark();
+
+ // Put the unsigned bytes
+ buf.putUnsigned( b );
+ buf.putUnsigned( s );
+ buf.putUnsigned( i );
+ buf.putUnsigned( l );
+
+ buf.reset();
+
+ // Read back the unsigned bytes
+ assertEquals( 0x0080, buf.getUnsigned() );
+ assertEquals( 0x0081, buf.getUnsigned() );
+ assertEquals( 0x0082, buf.getUnsigned() );
+ assertEquals( 0x0083, buf.getUnsigned() );
+ }
+
+ @Test
+ public void testPutUnsignedIndex() {
+ IoBuffer buf = IoBuffer.allocate(4);
+ byte b = (byte)0x80; // We should get 0x0080
+ short s = (short)0x8F81; // We should get 0x0081
+ int i = 0x8FFFFF82; // We should get 0x0082
+ long l = 0x8FFFFFFFFFFFFF83L; // We should get 0x0083
+
+ buf.mark();
+
+ // Put the unsigned bytes
+ buf.putUnsigned( 3, b );
+ buf.putUnsigned( 2, s );
+ buf.putUnsigned( 1, i );
+ buf.putUnsigned( 0, l );
+
+ buf.reset();
+
+ // Read back the unsigned bytes
+ assertEquals( 0x0083, buf.getUnsigned() );
+ assertEquals( 0x0082, buf.getUnsigned() );
+ assertEquals( 0x0081, buf.getUnsigned() );
+ assertEquals( 0x0080, buf.getUnsigned() );
+ }
@Test
public void testIndexOf() throws Exception {