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 15:27:45 UTC
svn commit: r1090588 - 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 13:27:44 2011
New Revision: 1090588
URL: http://svn.apache.org/viewvc?rev=1090588&view=rev
Log:
o Added the putUnsignedShort() and putUnsignedShort(index) methods
o Added some tests
o Added some Javadoc
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=1090588&r1=1090587&r2=1090588&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 13:27:44 2011
@@ -901,6 +901,86 @@ public abstract class AbstractIoBuffer e
* {@inheritDoc}
*/
@Override
+ public final IoBuffer putUnsignedShort(byte value) {
+ autoExpand(2);
+ buf().putShort( (short)((short)value&0x00ff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(int index, byte value) {
+ autoExpand(index, 2);
+ buf().putShort( (short)((short)value&0x00ff) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(short value) {
+ autoExpand(2);
+ buf().putShort( value );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(int index, short value) {
+ autoExpand(index, 2);
+ buf().putShort( value );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(int value) {
+ autoExpand(2);
+ buf().putShort( (short)value );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(int index, int value) {
+ autoExpand(index, 2);
+ buf().putShort( (short)value );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(long value) {
+ autoExpand(2);
+ buf().putShort( (short)(value) );
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final IoBuffer putUnsignedShort(int index, long value) {
+ autoExpand(index, 2);
+ buf().putShort( (short)(value) );
+ 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=1090588&r1=1090587&r2=1090588&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 13:27:44 2011
@@ -751,83 +751,159 @@ public abstract class IoBuffer implement
/**
* Writes an unsigned byte into the ByteBuffer
+ * @param value the byte to write
*/
public abstract IoBuffer putUnsigned(byte value);
/**
* Writes an unsigned byte into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the byte to write
*/
public abstract IoBuffer putUnsigned(int index, byte value);
/**
* Writes an unsigned byte into the ByteBuffer
+ * @param value the short to write
*/
public abstract IoBuffer putUnsigned(short value);
/**
* Writes an unsigned byte into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the short to write
*/
public abstract IoBuffer putUnsigned(int index, short value);
/**
* Writes an unsigned byte into the ByteBuffer
+ * @param value the int to write
*/
public abstract IoBuffer putUnsigned(int value);
/**
* Writes an unsigned byte into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the int to write
*/
public abstract IoBuffer putUnsigned(int index, int value);
/**
* Writes an unsigned byte into the ByteBuffer
+ * @param value the long to write
*/
public abstract IoBuffer putUnsigned(long value);
/**
* Writes an unsigned byte into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the long to write
*/
public abstract IoBuffer putUnsigned(int index, long value);
/**
* Writes an unsigned int into the ByteBuffer
+ * @param value the byte to write
*/
public abstract IoBuffer putUnsignedInt(byte value);
/**
* Writes an unsigned int into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the byte to write
*/
public abstract IoBuffer putUnsignedInt(int index, byte value);
/**
* Writes an unsigned int into the ByteBuffer
+ * @param value the short to write
*/
public abstract IoBuffer putUnsignedInt(short value);
/**
* Writes an unsigned int into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the short to write
*/
public abstract IoBuffer putUnsignedInt(int index, short value);
/**
* Writes an unsigned int into the ByteBuffer
+ * @param value the int to write
*/
public abstract IoBuffer putUnsignedInt(int value);
/**
* Writes an unsigned int into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the int to write
*/
public abstract IoBuffer putUnsignedInt(int index, int value);
/**
* Writes an unsigned int into the ByteBuffer
+ * @param value the long to write
*/
public abstract IoBuffer putUnsignedInt(long value);
/**
* Writes an unsigned int into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the long to write
*/
public abstract IoBuffer putUnsignedInt(int index, long value);
+
+ /**
+ * Writes an unsigned short into the ByteBuffer
+ * @param value the byte to write
+ */
+ public abstract IoBuffer putUnsignedShort(byte value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the byte to write
+ */
+ public abstract IoBuffer putUnsignedShort(int index, byte value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer
+ * @param value the short to write
+ */
+ public abstract IoBuffer putUnsignedShort(short value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the short to write
+ */
+ public abstract IoBuffer putUnsignedShort(int index, short value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer
+ * @param value the int to write
+ */
+ public abstract IoBuffer putUnsignedShort(int value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the int to write
+ */
+ public abstract IoBuffer putUnsignedShort(int index, int value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer
+ * @param value the long to write
+ */
+ public abstract IoBuffer putUnsignedShort(long value);
+
+ /**
+ * Writes an unsigned Short into the ByteBuffer at a specified position
+ * @param index the position in the buffer to write the value
+ * @param value the long to write
+ */
+ public abstract IoBuffer putUnsignedShort(int index, long value);
/**
* @see ByteBuffer#getInt(int)
@@ -836,6 +912,7 @@ public abstract class IoBuffer implement
/**
* Reads four bytes unsigned integer.
+ * @param index the position in the buffer to write the value
*/
public abstract long getUnsignedInt(int index);
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=1090588&r1=1090587&r2=1090588&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 13:27:44 2011
@@ -400,6 +400,54 @@ public class IoBufferWrapper extends IoB
buf.putUnsignedInt(index, value);
return this;
}
+
+ @Override
+ public IoBuffer putUnsignedShort(byte value) {
+ buf.putUnsignedShort(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(int index, byte value) {
+ buf.putUnsignedShort(index, value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(short value) {
+ buf.putUnsignedShort(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(int index, short value) {
+ buf.putUnsignedShort(index, value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(int value) {
+ buf.putUnsignedShort(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(int index, int value) {
+ buf.putUnsignedShort(index, value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(long value) {
+ buf.putUnsignedShort(value);
+ return this;
+ }
+
+ @Override
+ public IoBuffer putUnsignedShort(int index, long value) {
+ buf.putUnsignedShort(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=1090588&r1=1090587&r2=1090588&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 13:27:44 2011
@@ -934,56 +934,6 @@ public class IoBufferTest {
}
@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 {
boolean direct = false;
for (int i = 0; i < 2; i++, direct = !direct) {
@@ -1333,9 +1283,109 @@ public class IoBufferTest {
}
@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 testPutUnsignedShort() {
+ IoBuffer buf = IoBuffer.allocate(8);
+ byte b = (byte)0x80; // We should get 0x0080
+ short s = (short)0x8181; // We should get 0x8181
+ int i = 0x82828282; // We should get 0x8282
+ long l = 0x8383838383838383L; // We should get 0x8383
+
+ buf.mark();
+
+ // Put the unsigned bytes
+ buf.putUnsignedShort( b );
+ buf.putUnsignedShort( s );
+ buf.putUnsignedShort( i );
+ buf.putUnsignedShort( l );
+
+ buf.reset();
+
+ // Read back the unsigned bytes
+ assertEquals( 0x0080L, buf.getUnsignedShort() );
+ assertEquals( 0x8181L, buf.getUnsignedShort() );
+ assertEquals( 0x8282L, buf.getUnsignedShort() );
+ assertEquals( 0x8383L, buf.getUnsignedShort() );
+ }
+
+ @Test
+ public void testPutUnsignedShortIndex() {
+ IoBuffer buf = IoBuffer.allocate(8);
+ 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.putUnsignedShort( 3, b );
+ buf.putUnsignedShort( 2, s );
+ buf.putUnsignedShort( 1, i );
+ buf.putUnsignedShort( 0, l );
+
+ buf.reset();
+
+ // Read back the unsigned bytes
+ assertEquals( 0x0080L, buf.getUnsignedShort() );
+ assertEquals( 0x8181L, buf.getUnsignedShort() );
+ assertEquals( 0x8282L, buf.getUnsignedShort() );
+ assertEquals( 0x8383L, buf.getUnsignedShort() );
+ }
+
+ @Test
public void testPutUnsignedInt() {
IoBuffer buf = IoBuffer.allocate(16);
- byte b = (byte)0x80; // We should get 0x00000080
+ 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
@@ -1358,9 +1408,9 @@ public class IoBufferTest {
}
@Test
- public void testPutUnsignedIntPosition() {
+ public void testPutUnsignedIntIndex() {
IoBuffer buf = IoBuffer.allocate(16);
- byte b = (byte)0x80; // We should get 0x00000080
+ 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