Search in sources :

Example 46 with InvalidMarkException

use of java.nio.InvalidMarkException in project j2objc by google.

the class ShortBufferTest method testSlice.

public void testSlice() {
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(buf.capacity() - 1);
    ShortBuffer slice = buf.slice();
    assertEquals(buf.isReadOnly(), slice.isReadOnly());
    assertEquals(buf.isDirect(), slice.isDirect());
    assertEquals(buf.order(), slice.order());
    assertEquals(slice.position(), 0);
    assertEquals(slice.limit(), buf.remaining());
    assertEquals(slice.capacity(), buf.remaining());
    try {
        slice.reset();
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
    // slice share the same content with buf
    if (!slice.isReadOnly()) {
        loadTestData1(slice);
        assertContentLikeTestData1(buf, 1, (short) 0, slice.capacity());
        buf.put(2, (short) 500);
        assertEquals(slice.get(1), 500);
    }
}
Also used : ShortBuffer(java.nio.ShortBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Aggregations

InvalidMarkException (java.nio.InvalidMarkException)46 ByteBuffer (java.nio.ByteBuffer)19 Buffer (java.nio.Buffer)12 CharBuffer (java.nio.CharBuffer)4 DoubleBuffer (java.nio.DoubleBuffer)4 FloatBuffer (java.nio.FloatBuffer)4 IntBuffer (java.nio.IntBuffer)4 LongBuffer (java.nio.LongBuffer)4 ShortBuffer (java.nio.ShortBuffer)4 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ImageOutputStream (javax.imageio.stream.ImageOutputStream)1