package net.morimekta.util.io;

import org.junit.Test;

import java.io.IOException;
import java.nio.ByteBuffer;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

/**
 * Testing for the ByteBufferInputStream and ByteBufferOutputStream.
 */
public class ByteBufferIOTest {
    @Test
    public void testHeapBuffer() throws IOException {
        byte[] data = new byte[]{9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4};

        ByteBuffer buffer = ByteBuffer.allocate(20);
        buffer.limit(20);
        ByteBufferOutputStream bbos = new ByteBufferOutputStream(buffer);

        bbos.write(0);
        bbos.write(data);
        bbos.write(data, 6, 2);

        buffer.flip();
        ByteBufferInputStream bbis = new ByteBufferInputStream(buffer);

        assertEquals(0, bbis.read());
        byte[] indata = new byte[data.length];
        assertEquals(16, bbis.read(indata));
        assertArrayEquals(data, indata);
        byte[] indata2 = new byte[data.length];
        assertEquals(2, bbis.read(indata2, 6, 2));
        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0},
                          indata2);
    }
}

@@ -782,32 +782,918 @@
 tream(buffer);%0A%0A
+        assertEquals(0, bbis.read());%0A        byte%5B%5D indata = new byte%5Bdata.length%5D;%0A        assertEquals(16, bbis.read(indata));%0A        assertArrayEquals(data, indata);%0A        byte%5B%5D indata2 = new byte%5Bdata.length%5D;%0A        assertEquals(2, bbis.read(indata2, 6, 2));%0A        assertArrayEquals(new byte%5B%5D%7B0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0%7D,%0A                          indata2);%0A    %7D%0A%0A    @Test%0A    public void testDirectBuffer() throws IOException %7B%0A        byte%5B%5D data = new byte%5B%5D%7B9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4%7D;%0A%0A        ByteBuffer buffer = ByteBuffer.allocateDirect(20);%0A        buffer.limit(20);%0A        ByteBufferOutputStream bbos = new ByteBufferOutputStream(buffer);%0A%0A        bbos.write(0);%0A        bbos.write(data);%0A        bbos.write(data, 6, 2);%0A%0A        buffer.flip();%0A        ByteBufferInputStream bbis = new ByteBufferInputStream(buffer);%0A%0A
         assertEq

Add test for direct buffers.