Code example for Buffer

Methods: capacitylimitmarkpositionreset, Buffer.limit, Buffer.position

0
    /* 
     * Class under test for Buffer limit(int) 
     */ 
    public static void testLimitint(Buffer buf) {
        // save state 
        int oldPosition = buf.position();
        int oldLimit = buf.limit();
         
        Buffer ret = buf.limit(buf.limit());
        assertSame(ret, buf);
 
        buf.mark();
        buf.limit(buf.capacity());
        assertEquals(buf.limit(), buf.capacity());
        // position should not change 
        assertEquals(buf.position(), oldPosition);
        // mark should be valid 
        buf.reset();
 
        if (buf.capacity() > 0) {
            buf.limit(buf.capacity());
            buf.position(buf.capacity());
            buf.mark();
            buf.limit(buf.capacity() - 1);
            // position should be the new limit 
            assertEquals(buf.position(), buf.limit());
            // mark should be invalid 
            try { 
                buf.reset();
                fail("Should throw Exception"); //$NON-NLS-1$
            } catch (InvalidMarkException e) {
                // expected 
            } 
        } 
         
        try { 
            buf.limit(-1);
            fail("Should throw Exception"); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // expected 
        } 
        try { 
            buf.limit(buf.capacity() + 1);
            fail("Should throw Exception"); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // expected 
        } 
 
        // restore state 
        buf.limit(oldLimit);
        buf.position(oldPosition);
    } 
 
    public static void testMark(Buffer buf) {
        // save state 
        int oldPosition = buf.position();
Contextual code suggestions in your IDE  Get Codota for Java