diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java index 24f729b7f..e24b2792d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java @@ -486,10 +486,10 @@ class TByteBufferImpl extends TByteBuffer { array[start + index + 1] = (byte) (value >> 8); array[start + index + 2] = (byte) (value >> 16); array[start + index + 3] = (byte) (value >> 24); - array[start + index + 4] = (byte) (value >> 24); - array[start + index + 5] = (byte) (value >> 24); - array[start + index + 6] = (byte) (value >> 24); - array[start + index + 7] = (byte) (value >> 24); + array[start + index + 4] = (byte) (value >> 32); + array[start + index + 5] = (byte) (value >> 40); + array[start + index + 6] = (byte) (value >> 48); + array[start + index + 7] = (byte) (value >> 56); } return this; } diff --git a/tests/src/test/java/org/teavm/classlib/java/nio/ByteBufferTest.java b/tests/src/test/java/org/teavm/classlib/java/nio/ByteBufferTest.java index b4dbe7264..3723fe57c 100644 --- a/tests/src/test/java/org/teavm/classlib/java/nio/ByteBufferTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/nio/ByteBufferTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.fail; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.InvalidMarkException; import java.nio.ReadOnlyBufferException; import org.junit.Test; @@ -715,6 +716,17 @@ public class ByteBufferTest { } catch (IndexOutOfBoundsException e) { // expected } + + buffer = ByteBuffer.wrap(array).order(ByteOrder.LITTLE_ENDIAN); + buffer.putLong(1, 0x2324252627282930L); + assertThat(buffer.get(1), is((byte) 0x30)); + assertThat(buffer.get(2), is((byte) 0x29)); + assertThat(buffer.get(3), is((byte) 0x28)); + assertThat(buffer.get(4), is((byte) 0x27)); + assertThat(buffer.get(5), is((byte) 0x26)); + assertThat(buffer.get(6), is((byte) 0x25)); + assertThat(buffer.get(7), is((byte) 0x24)); + assertThat(buffer.get(8), is((byte) 0x23)); } @Test