Fixed issue: NETTY-176 toByteBuffer() and slice() sometimes do not respect byte order

* Added tests to make sure all ChannelBuffer implementations are fixed
* Fixed the byte order problem in HeapChannelBuffer
This commit is contained in:
Trustin Lee 2009-06-17 08:08:11 +00:00
parent b9cd9de5ed
commit 70e90fc85e
2 changed files with 11 additions and 1 deletions

View File

@ -198,7 +198,7 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
} }
public ByteBuffer toByteBuffer(int index, int length) { public ByteBuffer toByteBuffer(int index, int length) {
return ByteBuffer.wrap(array, index, length); return ByteBuffer.wrap(array, index, length).order(order());
} }
public String toString(int index, int length, String charsetName) { public String toString(int index, int length, String charsetName) {

View File

@ -1443,6 +1443,11 @@ public abstract class AbstractChannelBufferTest {
assertTrue(buffer.getByte(1) == duplicate.getByte(1)); assertTrue(buffer.getByte(1) == duplicate.getByte(1));
} }
@Test
public void testSlice() throws Exception {
assertEquals(buffer.order(), buffer.slice(1, buffer.capacity() - 1).order());
}
@Test @Test
public void testEquals() { public void testEquals() {
assertFalse(buffer.equals(null)); assertFalse(buffer.equals(null));
@ -1561,6 +1566,11 @@ public abstract class AbstractChannelBufferTest {
} }
} }
@Test
public void testToByteBuffer3() {
assertEquals(buffer.order(), buffer.toByteBuffer().order());
}
@Test @Test
public void testToByteBuffers1() { public void testToByteBuffers1() {
byte[] value = new byte[buffer.capacity()]; byte[] value = new byte[buffer.capacity()];