@@ -0,0 +1,2598 @@
+import java.nio.ByteBuffer;%0A%0Apublic class Buffers %7B%0A  static %7B%0A    System.loadLibrary(%22test%22);%0A  %7D%0A%0A  private static void expect(boolean v) %7B%0A    if (! v) throw new RuntimeException();%0A  %7D%0A%0A  private static void test(Factory factory1, Factory factory2) %7B%0A    %7B final int size = 64;%0A      ByteBuffer b1 = factory1.allocate(size);%0A      try %7B%0A        for (int i = 0; i %3C size; ++i)%0A          b1.put(i, (byte) 42);%0A%0A        for (int i = 0; i %3C size; ++i)%0A          expect(b1.get(i) == 42);%0A%0A        for (int i = 0; i %3C size / 2; ++i)%0A          b1.putShort(i * 2, (short) -12345);%0A%0A        for (int i = 0; i %3C size / 2; ++i)%0A          expect(b1.getShort(i * 2) == -12345);%0A%0A        for (int i = 0; i %3C size / 4; ++i)%0A          b1.putInt(i * 4, 0x12345678);%0A%0A        for (int i = 0; i %3C size / 4; ++i)%0A          expect(b1.getInt(i * 4) == 0x12345678);%0A%0A        for (int i = 0; i %3C size / 8; ++i)%0A          b1.putLong(i * 8, 0x1234567890ABCDEFL);%0A%0A        for (int i = 0; i %3C size / 8; ++i)%0A          expect(b1.getLong(i * 8) ==  0x1234567890ABCDEFL);%0A%0A        ByteBuffer b2 = factory2.allocate(size);%0A        try %7B%0A          b2.put(b1);%0A%0A          for (int i = 0; i %3C size / 8; ++i)%0A            expect(b2.getLong(i * 8) ==  0x1234567890ABCDEFL);%0A%0A        %7D finally %7B%0A          factory2.dispose(b2);%0A        %7D%0A      %7D finally %7B%0A        factory1.dispose(b1);%0A      %7D%0A    %7D%0A  %7D%0A%0A  private static native ByteBuffer allocateNative(int capacity);%0A%0A  private static native void freeNative(ByteBuffer b);%0A%0A  public static void main(String%5B%5D args) %7B%0A    Factory array = new Factory() %7B%0A        public ByteBuffer allocate(int capacity) %7B%0A          return ByteBuffer.allocate(capacity);%0A        %7D%0A%0A        public void dispose(ByteBuffer b) %7B%0A          // ignore%0A        %7D%0A      %7D;%0A%0A    Factory direct = new Factory() %7B%0A        public ByteBuffer allocate(int capacity) %7B%0A          return ByteBuffer.allocateDirect(capacity);%0A        %7D%0A%0A        public void dispose(ByteBuffer b) %7B%0A          // ignore%0A        %7D%0A      %7D;%0A%0A    Factory native_ = new Factory() %7B%0A        public ByteBuffer allocate(int capacity) %7B%0A          return allocateNative(capacity);%0A        %7D%0A%0A        public void dispose(ByteBuffer b) %7B%0A          freeNative(b);%0A        %7D%0A      %7D;%0A%0A    test(array, array);%0A    test(array, direct);%0A    test(array, native_);%0A%0A    test(direct, array);%0A    test(direct, direct);%0A    test(direct, native_);%0A%0A    test(native_, array);%0A    test(native_, direct);%0A    test(native_, native_);%0A  %7D%0A%0A  private interface Factory %7B%0A    public ByteBuffer allocate(int capacity);%0A%0A    public void dispose(ByteBuffer b);%0A  %7D%0A%7D%0A

add Buffers test